Skip to content

Commit

Permalink
Issue #8578 - Changes from review
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <[email protected]>
  • Loading branch information
joakime committed Sep 12, 2022
1 parent a6a386a commit 8eba1c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
17 changes: 4 additions & 13 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,26 +1278,17 @@ public String getRequestedSessionId()
@Override
public String getRequestURI()
{
if (_uri == null)
return null;
if (HttpMethod.CONNECT.is(getMethod()))
return _uri.getAuthority();
else
return _uri.getPath();
return _uri == null ? null : _uri.getPath();
}

@Override
public StringBuffer getRequestURL()
{
final StringBuffer url = new StringBuffer(128);
URIUtil.appendSchemeHostPort(url, getScheme(), getServerName(), getServerPort());
// only add RequestURI if not a CONNECT method
if (!HttpMethod.CONNECT.is(getMethod()))
{
String requestURI = getRequestURI();
if (requestURI != null)
url.append(requestURI);
}
String path = getRequestURI();
if (path != null)
url.append(path);
return url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,14 +858,14 @@ public void testContentTypeEncoding() throws Exception
}

@Test
public void testConnectRequestURL() throws Exception
public void testConnectRequestURLSameAsHost() 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());
resultRequestURL.set(request.getRequestURL().toString());
resultRequestURI.set(request.getRequestURI());
return true;
};

Expand All @@ -876,8 +876,31 @@ public void testConnectRequestURL() throws Exception
"\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"));
assertThat("request.getRequestURL", resultRequestURL.get(), is("http://myhost:9999/"));
assertThat("request.getRequestURI", resultRequestURI.get(), is("/"));
}

@Test
public void testConnectRequestURLDifferentThanHost() throws Exception
{
final AtomicReference<String> resultRequestURL = new AtomicReference<>();
final AtomicReference<String> resultRequestURI = new AtomicReference<>();
_handler._checker = (request, response) ->
{
resultRequestURL.set(request.getRequestURL().toString());
resultRequestURI.set(request.getRequestURI());
return true;
};

String rawResponse = _connector.getResponse(
"CONNECT myhost:9999 HTTP/1.1\n" +
"Host: otherhost:8888\n" + // per spec, this is ignored if request-target is authority-form
"Connection: close\n" +
"\n");
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
assertThat(response.getStatus(), is(HttpStatus.OK_200));
assertThat("request.getRequestURL", resultRequestURL.get(), is("http://myhost:9999/"));
assertThat("request.getRequestURI", resultRequestURI.get(), is("/"));
}

@Test
Expand Down

0 comments on commit 8eba1c9

Please sign in to comment.