Skip to content

Commit 5944ff4

Browse files
committed
Issue #8578 - Changes from review
Signed-off-by: Joakim Erdfelt <[email protected]>
1 parent 48c16de commit 5944ff4

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ public boolean isExpecting102Processing()
102102
}
103103

104104
@Override
105-
public boolean startRequest(String method, String uri, HttpVersion version)
105+
public boolean startRequest(String method, String requestTarget, HttpVersion version)
106106
{
107107
_metadata.setMethod(method);
108-
_metadata.getURI().parseRequestTarget(method, uri);
108+
_metadata.getURI().parseRequestTarget(method, requestTarget);
109109
_metadata.setHttpVersion(version);
110110
_unknownExpectation = false;
111111
_expect100Continue = false;
@@ -127,7 +127,7 @@ public void parsedHeader(HttpField field)
127127
break;
128128

129129
case HOST:
130-
if (!_metadata.getURI().isAbsolute() && field instanceof HostPortHttpField)
130+
if (!HttpMethod.CONNECT.is(_metadata.getMethod()) && !_metadata.getURI().isAbsolute() && field instanceof HostPortHttpField)
131131
{
132132
HostPortHttpField hp = (HostPortHttpField)field;
133133
_metadata.getURI().setAuthority(hp.getHost(), hp.getPort());

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

+4-14
Original file line numberDiff line numberDiff line change
@@ -1341,17 +1341,7 @@ public String getRequestedSessionId()
13411341
public String getRequestURI()
13421342
{
13431343
MetaData.Request metadata = _metaData;
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();
1344+
return (metadata == null) ? null : metadata.getURI().getPath();
13551345
}
13561346

13571347
/*
@@ -1362,9 +1352,9 @@ public StringBuffer getRequestURL()
13621352
{
13631353
final StringBuffer url = new StringBuffer(128);
13641354
URIUtil.appendSchemeHostPort(url, getScheme(), getServerName(), getServerPort());
1365-
// only add RequestURI if not a CONNECT method
1366-
if (!HttpMethod.CONNECT.is(getMethod()))
1367-
url.append(getRequestURI());
1355+
String path = getRequestURI();
1356+
if (path != null)
1357+
url.append(path);
13681358
return url;
13691359
}
13701360

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

+29-5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import static org.hamcrest.Matchers.containsString;
8585
import static org.hamcrest.Matchers.is;
8686
import static org.hamcrest.Matchers.not;
87+
import static org.hamcrest.Matchers.nullValue;
8788
import static org.hamcrest.Matchers.startsWith;
8889
import static org.junit.jupiter.api.Assertions.assertEquals;
8990
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -874,14 +875,14 @@ public boolean check(HttpServletRequest request, HttpServletResponse response)
874875
}
875876

876877
@Test
877-
public void testConnectRequestURL() throws Exception
878+
public void testConnectRequestURLSameAsHost() throws Exception
878879
{
879880
final AtomicReference<String> resultRequestURL = new AtomicReference<>();
880881
final AtomicReference<String> resultRequestURI = new AtomicReference<>();
881882
_handler._checker = (request, response) ->
882883
{
883-
resultRequestURL.set("" + request.getRequestURL());
884-
resultRequestURI.set("" + request.getRequestURI());
884+
resultRequestURL.set(request.getRequestURL().toString());
885+
resultRequestURI.set(request.getRequestURI());
885886
return true;
886887
};
887888

@@ -892,8 +893,31 @@ public void testConnectRequestURL() throws Exception
892893
"\n");
893894
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
894895
assertThat(response.getStatus(), is(HttpStatus.OK_200));
895-
assertThat(resultRequestURL.get(), is("http://myhost:9999"));
896-
assertThat(resultRequestURI.get(), is("myhost:9999"));
896+
assertThat("request.getRequestURL", resultRequestURL.get(), is("http://myhost:9999"));
897+
assertThat("request.getRequestURI", resultRequestURI.get(), is(nullValue()));
898+
}
899+
900+
@Test
901+
public void testConnectRequestURLDifferentThanHost() throws Exception
902+
{
903+
final AtomicReference<String> resultRequestURL = new AtomicReference<>();
904+
final AtomicReference<String> resultRequestURI = new AtomicReference<>();
905+
_handler._checker = (request, response) ->
906+
{
907+
resultRequestURL.set(request.getRequestURL().toString());
908+
resultRequestURI.set(request.getRequestURI());
909+
return true;
910+
};
911+
912+
String rawResponse = _connector.getResponse(
913+
"CONNECT myhost:9999 HTTP/1.1\n" +
914+
"Host: otherhost:8888\n" + // per spec, this is ignored if request-target is authority-form
915+
"Connection: close\n" +
916+
"\n");
917+
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
918+
assertThat(response.getStatus(), is(HttpStatus.OK_200));
919+
assertThat("request.getRequestURL", resultRequestURL.get(), is("http://myhost:9999"));
920+
assertThat("request.getRequestURI", resultRequestURI.get(), is(nullValue()));
897921
}
898922

899923
@Test

0 commit comments

Comments
 (0)