diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 55f9b297aa3..082d05e7339 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -1278,7 +1278,12 @@ public class Request implements HttpServletRequest @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 @@ -1286,7 +1291,13 @@ public class Request implements HttpServletRequest { 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; } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index f2b58d9395b..71b226bfac5 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -57,6 +57,7 @@ import org.eclipse.jetty.http.HttpCookie; 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; @@ -856,6 +857,29 @@ public class RequestTest assertEquals(" x=z; ", results.get(i)); } + @Test + public void testConnectRequestURL() throws Exception + { + final AtomicReference resultRequestURL = new AtomicReference<>(); + final AtomicReference 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 {