Skip to content

Commit d3c7ee3

Browse files
committed
Issue #8578 - restore backward compat of getRequestURL and getRequestURI when working with CONNECT method
Signed-off-by: Joakim Erdfelt <[email protected]>
1 parent 06f2fa4 commit d3c7ee3

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

jetty-server/src/main/java/org/eclipse/jetty/server/Request.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,17 @@ public String getRequestedSessionId()
13411341
public String getRequestURI()
13421342
{
13431343
MetaData.Request metadata = _metaData;
1344-
return (metadata == null) ? null : metadata.getURI().getPath();
1344+
if (metadata == null)
1345+
return null;
1346+
HttpURI uri = metadata.getURI();
1347+
if (uri == null)
1348+
return null;
1349+
// maintain backward compat for CONNECT method
1350+
if (HttpMethod.CONNECT.is(getMethod()))
1351+
return uri.getAuthority();
1352+
else
1353+
// spec compliant path
1354+
return uri.getPath();
13451355
}
13461356

13471357
/*
@@ -1352,7 +1362,9 @@ public StringBuffer getRequestURL()
13521362
{
13531363
final StringBuffer url = new StringBuffer(128);
13541364
URIUtil.appendSchemeHostPort(url, getScheme(), getServerName(), getServerPort());
1355-
url.append(getRequestURI());
1365+
// only add RequestURI if not a CONNECT method
1366+
if (!HttpMethod.CONNECT.is(getMethod()))
1367+
url.append(getRequestURI());
13561368
return url;
13571369
}
13581370

jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java

+21
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.eclipse.jetty.http.BadMessageException;
5656
import org.eclipse.jetty.http.HttpCompliance;
5757
import org.eclipse.jetty.http.HttpComplianceSection;
58+
import org.eclipse.jetty.http.HttpStatus;
5859
import org.eclipse.jetty.http.HttpTester;
5960
import org.eclipse.jetty.http.MimeTypes;
6061
import org.eclipse.jetty.io.Connection;
@@ -872,6 +873,26 @@ public boolean check(HttpServletRequest request, HttpServletResponse response)
872873
assertEquals(" x=z; ", results.get(i++));
873874
}
874875

876+
@Test
877+
public void testConnectRequestURL() throws Exception
878+
{
879+
final AtomicReference<String> result = new AtomicReference<>();
880+
_handler._checker = (request, response) ->
881+
{
882+
result.set("" + request.getRequestURL());
883+
return true;
884+
};
885+
886+
String rawResponse = _connector.getResponse(
887+
"CONNECT myhost:9999 HTTP/1.1\n" +
888+
"Host: myhost:9999\n" +
889+
"Connection: close\n" +
890+
"\n");
891+
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
892+
assertThat(response.getStatus(), is(HttpStatus.OK_200));
893+
assertThat(result.get(), is("http://myhost:9999"));
894+
}
895+
875896
@Test
876897
public void testHostPort() throws Exception
877898
{

0 commit comments

Comments
 (0)