Issue #8578 - restore backward compat of getRequestURL and getRequestURI when working with CONNECT method
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
3df45b92de
commit
a6a386a6cc
|
@ -1278,7 +1278,12 @@ public class Request implements HttpServletRequest
|
||||||
@Override
|
@Override
|
||||||
public String getRequestURI()
|
public String getRequestURI()
|
||||||
{
|
{
|
||||||
return _uri == null ? null : _uri.getPath();
|
if (_uri == null)
|
||||||
|
return null;
|
||||||
|
if (HttpMethod.CONNECT.is(getMethod()))
|
||||||
|
return _uri.getAuthority();
|
||||||
|
else
|
||||||
|
return _uri.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1286,7 +1291,13 @@ public class Request implements HttpServletRequest
|
||||||
{
|
{
|
||||||
final StringBuffer url = new StringBuffer(128);
|
final StringBuffer url = new StringBuffer(128);
|
||||||
URIUtil.appendSchemeHostPort(url, getScheme(), getServerName(), getServerPort());
|
URIUtil.appendSchemeHostPort(url, getScheme(), getServerName(), getServerPort());
|
||||||
url.append(getRequestURI());
|
// only add RequestURI if not a CONNECT method
|
||||||
|
if (!HttpMethod.CONNECT.is(getMethod()))
|
||||||
|
{
|
||||||
|
String requestURI = getRequestURI();
|
||||||
|
if (requestURI != null)
|
||||||
|
url.append(requestURI);
|
||||||
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ import org.eclipse.jetty.http.HttpCookie;
|
||||||
import org.eclipse.jetty.http.HttpField;
|
import org.eclipse.jetty.http.HttpField;
|
||||||
import org.eclipse.jetty.http.HttpFields;
|
import org.eclipse.jetty.http.HttpFields;
|
||||||
import org.eclipse.jetty.http.HttpHeader;
|
import org.eclipse.jetty.http.HttpHeader;
|
||||||
|
import org.eclipse.jetty.http.HttpStatus;
|
||||||
import org.eclipse.jetty.http.HttpTester;
|
import org.eclipse.jetty.http.HttpTester;
|
||||||
import org.eclipse.jetty.http.HttpURI;
|
import org.eclipse.jetty.http.HttpURI;
|
||||||
import org.eclipse.jetty.http.HttpVersion;
|
import org.eclipse.jetty.http.HttpVersion;
|
||||||
|
@ -856,6 +857,29 @@ public class RequestTest
|
||||||
assertEquals(" x=z; ", results.get(i));
|
assertEquals(" x=z; ", results.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConnectRequestURL() throws Exception
|
||||||
|
{
|
||||||
|
final AtomicReference<String> resultRequestURL = new AtomicReference<>();
|
||||||
|
final AtomicReference<String> resultRequestURI = new AtomicReference<>();
|
||||||
|
_handler._checker = (request, response) ->
|
||||||
|
{
|
||||||
|
resultRequestURL.set("" + request.getRequestURL());
|
||||||
|
resultRequestURI.set("" + request.getRequestURI());
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
String rawResponse = _connector.getResponse(
|
||||||
|
"CONNECT myhost:9999 HTTP/1.1\n" +
|
||||||
|
"Host: myhost:9999\n" +
|
||||||
|
"Connection: close\n" +
|
||||||
|
"\n");
|
||||||
|
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
|
||||||
|
assertThat(response.getStatus(), is(HttpStatus.OK_200));
|
||||||
|
assertThat(resultRequestURL.get(), is("http://myhost:9999"));
|
||||||
|
assertThat(resultRequestURI.get(), is("myhost:9999"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostPort() throws Exception
|
public void testHostPort() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue