diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java index 0c4121896f1..15289d5016f 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java @@ -97,6 +97,8 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding Resource resource = Resource.newResource(app.getOriginId()); File file = resource.getFile(); jettyXmlConfig.getIdMap().put("Server",app.getDeploymentManager().getServer()); + jettyXmlConfig.getProperties().put("jetty.home",System.getProperty("jetty.home",".")); + jettyXmlConfig.getProperties().put("jetty.base",System.getProperty("jetty.base",".")); jettyXmlConfig.getProperties().put("jetty.webapp",file.getCanonicalPath()); jettyXmlConfig.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath()); diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java index 0c2968222c9..9771b5ccc4e 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java @@ -167,4 +167,24 @@ public class HttpURITest assertEquals("p2",uri.getParam()); assertEquals("other=123456",uri.getQuery()); } + + @Test + public void testSchemeAndOrAuthority() throws Exception + { + HttpURI uri = new HttpURI("/path/info"); + assertEquals("/path/info",uri.toString()); + + uri.setAuthority("host",0); + assertEquals("//host/path/info",uri.toString()); + + uri.setAuthority("host",8888); + assertEquals("//host:8888/path/info",uri.toString()); + + uri.setScheme("http"); + assertEquals("http://host:8888/path/info",uri.toString()); + + uri.setAuthority(null,0); + assertEquals("http:/path/info",uri.toString()); + + } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java index 37401190049..8204b8b7e17 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java @@ -31,7 +31,6 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeaderValue; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpParser; -import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpVersion; @@ -130,8 +129,6 @@ class HttpChannelOverHttp extends HttpChannel implements HttpParser.RequestHandl if (!_metadata.getURI().isAbsolute() && field instanceof HostPortHttpField) { HostPortHttpField hp = (HostPortHttpField)field; - // Set scheme default value as 'http' (can be overridden later in SecureRequestCustomizer) - _metadata.getURI().setScheme(HttpScheme.HTTP.asString()); _metadata.getURI().setAuthority(hp.getHost(),hp.getPort()); } break; 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 d92cb3a03ea..fbc42e0708b 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 @@ -1353,7 +1353,7 @@ public class Request implements HttpServletRequest @Override public String getScheme() { - String scheme=_metadata.getURI().getScheme(); + String scheme=_metadata==null?null:_metadata.getURI().getScheme(); return scheme==null?HttpScheme.HTTP.asString():scheme; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java b/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java index 77d4d9206c1..7dc74588d80 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java @@ -68,8 +68,11 @@ public class SecureRequestCustomizer implements HttpConfiguration.Customizer { if (request.getHttpChannel().getEndPoint() instanceof DecryptedEndPoint) { - request.setScheme(HttpScheme.HTTPS.asString()); request.setSecure(true); + + if (request.getHttpURI().getScheme()==null) + request.setScheme(HttpScheme.HTTPS.asString()); + SslConnection.DecryptedEndPoint ssl_endp = (DecryptedEndPoint)request.getHttpChannel().getEndPoint(); SslConnection sslConnection = ssl_endp.getSslConnection(); SSLEngine sslEngine=sslConnection.getSSLEngine(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index c2000819676..f6f6781670d 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -533,6 +533,7 @@ public class ResponseTest Response response = newResponse(); Request request = response.getHttpChannel().getRequest(); + request.setScheme("http"); request.setAuthority(host,port); request.setURIPathQuery("/path/info;param;jsessionid=12345?query=0&more=1#target"); request.setContextPath("/path"); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/DebugHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/DebugHandlerTest.java index d0bbb816245..56f7252fc91 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/DebugHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/DebugHandlerTest.java @@ -158,7 +158,7 @@ public class DebugHandlerTest req.getString("/foo/bar?a=b"); String log = capturedLog.toString(StandardCharsets.UTF_8.name()); - String expectedThreadName = String.format("http://%s:%s/foo/bar?a=b",serverURI.getHost(),serverURI.getPort()); + String expectedThreadName = String.format("//%s:%s/foo/bar?a=b",serverURI.getHost(),serverURI.getPort()); assertThat("ThreadName", log, containsString(expectedThreadName)); // Look for bad/mangled/duplicated schemes assertThat("ThreadName", log, not(containsString("http:"+expectedThreadName))); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/RequestLogTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/RequestLogTest.java index 21ff6f04612..61566775ddb 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/RequestLogTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/RequestLogTest.java @@ -66,6 +66,7 @@ public class RequestLogTest _server.stop(); } + @Test public void testNotHandled() throws Exception { @@ -73,6 +74,30 @@ public class RequestLogTest String log = _log.exchange(null,5,TimeUnit.SECONDS); assertThat(log,containsString("GET /foo HTTP/1.0\" 404 ")); } + + @Test + public void testRequestLine() throws Exception + { + _connector.getResponses("GET /foo?data=1 HTTP/1.0\nhost: host:80\n\n"); + String log = _log.exchange(null,5,TimeUnit.SECONDS); + // TODO should be without host (https://bugs.eclipse.org/bugs/show_bug.cgi?id=480276) + // assertThat(log,containsString("GET /foo?data=1 HTTP/1.0\" 200 ")); + assertThat(log,containsString("GET //host:80/foo?data=1 HTTP/1.0\" 200 ")); + + _connector.getResponses("GET //host/foo?data=1 HTTP/1.0\n\n"); + log = _log.exchange(null,5,TimeUnit.SECONDS); + assertThat(log,containsString("GET //host/foo?data=1 HTTP/1.0\" 200 ")); + + _connector.getResponses("GET //absolute:80/foo?data=1 HTTP/1.0\nhost: host:80\n\n"); + log = _log.exchange(null,5,TimeUnit.SECONDS); + // TODO should it be with absolute? (https://bugs.eclipse.org/bugs/show_bug.cgi?id=480276) + // assertThat(log,containsString("GET //absolute:80/foo?data=1 HTTP/1.0\" 200 ")); + assertThat(log,containsString("GET //host:80/foo?data=1 HTTP/1.0\" 200 ")); + + _connector.getResponses("GET http://host:80/foo?data=1 HTTP/1.0\n\n"); + log = _log.exchange(null,5,TimeUnit.SECONDS); + assertThat(log,containsString("GET http://host:80/foo?data=1 HTTP/1.0\" 200 ")); + } @Test public void testSmallData() throws Exception diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index 57b5b503004..f899d9809ed 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -35,7 +35,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.servlet.Servlet; import javax.servlet.ServletContext; import javax.servlet.ServletRegistration.Dynamic; import javax.servlet.ServletSecurityElement; @@ -60,7 +59,6 @@ import org.eclipse.jetty.servlet.ErrorPageErrorHandler; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.util.AttributesMap; -import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.URIUtil;