Skip to content

Commit

Permalink
Issue #8578 - restore backward compat of getRequestURL and getRequest…
Browse files Browse the repository at this point in the history
…URI when working with CONNECT method

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Sep 9, 2022
1 parent 06f2fa4 commit d3c7ee3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
16 changes: 14 additions & 2 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Expand Up @@ -1341,7 +1341,17 @@ public String getRequestedSessionId()
public String getRequestURI()
{
MetaData.Request metadata = _metaData;
return (metadata == null) ? null : metadata.getURI().getPath();
if (metadata == null)
return null;
HttpURI uri = metadata.getURI();
if (uri == null)
return null;
// maintain backward compat for CONNECT method
if (HttpMethod.CONNECT.is(getMethod()))
return uri.getAuthority();
else
// spec compliant path
return uri.getPath();
}

/*
Expand All @@ -1352,7 +1362,9 @@ public StringBuffer getRequestURL()
{
final StringBuffer url = new StringBuffer(128);
URIUtil.appendSchemeHostPort(url, getScheme(), getServerName(), getServerPort());
url.append(getRequestURI());
// only add RequestURI if not a CONNECT method
if (!HttpMethod.CONNECT.is(getMethod()))
url.append(getRequestURI());
return url;
}

Expand Down
Expand Up @@ -55,6 +55,7 @@
import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.HttpCompliance;
import org.eclipse.jetty.http.HttpComplianceSection;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.io.Connection;
Expand Down Expand Up @@ -872,6 +873,26 @@ public boolean check(HttpServletRequest request, HttpServletResponse response)
assertEquals(" x=z; ", results.get(i++));
}

@Test
public void testConnectRequestURL() throws Exception
{
final AtomicReference<String> result = new AtomicReference<>();
_handler._checker = (request, response) ->
{
result.set("" + request.getRequestURL());
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(result.get(), is("http://myhost:9999"));
}

@Test
public void testHostPort() throws Exception
{
Expand Down

0 comments on commit d3c7ee3

Please sign in to comment.