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 <[email protected]>
  • Loading branch information
joakime committed Sep 9, 2022
1 parent 3df45b9 commit a6a386a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
15 changes: 13 additions & 2 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -1278,15 +1278,26 @@ public String getRequestedSessionId()
@Override
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
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()))
{
String requestURI = getRequestURI();
if (requestURI != null)
url.append(requestURI);
}
return url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.HttpVersion;
Expand Down Expand Up @@ -856,6 +857,29 @@ public void testContentTypeEncoding() throws Exception
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
public void testHostPort() throws Exception
{
Expand Down

0 comments on commit a6a386a

Please sign in to comment.