From 4679565fd5b33fc009a9193bc5f65c6f67436e75 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 22 Oct 2018 13:10:05 -0500 Subject: [PATCH] Issue #3011 - Moving HttpCompliance to HttpConfiguration Signed-off-by: Joakim Erdfelt --- .../jetty/server/HttpConfiguration.java | 12 ++++++++++++ .../jetty/server/HttpConnectionFactory.java | 19 ++----------------- .../jetty/server/HttpConnectionTest.java | 10 +++++----- .../servlet/ComplianceViolations2616Test.java | 3 ++- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java index a6a19ff5d47..7af7ba11e6e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java @@ -24,6 +24,7 @@ import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import org.eclipse.jetty.http.CookieCompliance; +import org.eclipse.jetty.http.HttpCompliance; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.util.Jetty; @@ -71,6 +72,7 @@ public class HttpConfiguration private boolean _useDirectByteBuffers = false; private long _minRequestDataRate; private long _minResponseDataRate; + private HttpCompliance _httpCompliance = HttpCompliance.RFC7230; private CookieCompliance _cookieCompliance = CookieCompliance.RFC6265; private MultiPartFormDataCompliance _multiPartCompliance = MultiPartFormDataCompliance.RFC7578; private boolean _notifyRemoteAsyncErrors = true; @@ -547,6 +549,16 @@ public class HttpConfiguration _minResponseDataRate = bytesPerSecond; } + public HttpCompliance getHttpCompliance() + { + return _httpCompliance; + } + + public void setHttpCompliance(HttpCompliance _httpCompliance) + { + this._httpCompliance = _httpCompliance; + } + public CookieCompliance getCookieCompliance() { return _cookieCompliance; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java index 6459b0394d1..708a5155641 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java @@ -32,7 +32,6 @@ import org.eclipse.jetty.util.annotation.Name; public class HttpConnectionFactory extends AbstractConnectionFactory implements HttpConfiguration.ConnectionFactory { private final HttpConfiguration _config; - private HttpCompliance _httpCompliance; private boolean _recordHttpComplianceViolations = false; public HttpConnectionFactory() @@ -41,15 +40,9 @@ public class HttpConnectionFactory extends AbstractConnectionFactory implements } public HttpConnectionFactory(@Name("config") HttpConfiguration config) - { - this(config,null); - } - - public HttpConnectionFactory(@Name("config") HttpConfiguration config, @Name("compliance") HttpCompliance compliance) { super(HttpVersion.HTTP_1_1.asString()); _config=config; - _httpCompliance=compliance==null?HttpCompliance.RFC7230:compliance; if (config==null) throw new IllegalArgumentException("Null HttpConfiguration"); addBean(_config); @@ -63,7 +56,7 @@ public class HttpConnectionFactory extends AbstractConnectionFactory implements public HttpCompliance getHttpCompliance() { - return _httpCompliance; + return _config.getHttpCompliance(); } public boolean isRecordHttpComplianceViolations() @@ -71,18 +64,10 @@ public class HttpConnectionFactory extends AbstractConnectionFactory implements return _recordHttpComplianceViolations; } - /** - * @param httpCompliance String value of {@link HttpCompliance} - */ - public void setHttpCompliance(HttpCompliance httpCompliance) - { - _httpCompliance = httpCompliance; - } - @Override public Connection newConnection(Connector connector, EndPoint endPoint) { - HttpConnection conn = new HttpConnection(_config, connector, endPoint, _httpCompliance,isRecordHttpComplianceViolations()); + HttpConnection conn = new HttpConnection(_config, connector, endPoint, getHttpCompliance(), isRecordHttpComplianceViolations()); return configure(conn, connector, endPoint); } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java index 811b22a8093..d29567e3c7c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java @@ -148,12 +148,12 @@ public class HttpConnectionTest @Test public void testHttp09_NoVersion() throws Exception { - connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616); + connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setHttpCompliance(HttpCompliance.RFC2616); String request = "GET / HTTP/0.9\r\n\r\n"; String response = connector.getResponse(request); assertThat(response, containsString("400 Bad Version")); - connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC7230); + connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setHttpCompliance(HttpCompliance.RFC7230); request = "GET / HTTP/0.9\r\n\r\n"; response = connector.getResponse(request); assertThat(response, containsString("400 Bad Version")); @@ -165,7 +165,7 @@ public class HttpConnectionTest @Test public void testHttp09_NoHeaders() throws Exception { - connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616); + connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setHttpCompliance(HttpCompliance.RFC2616); // header looking like another request is ignored String request = "GET /one\r\nGET :/two\r\n\r\n"; String response = BufferUtil.toString(connector.executeRequest(request).waitForOutput(10,TimeUnit.SECONDS)); @@ -179,7 +179,7 @@ public class HttpConnectionTest @Test public void testHttp09_MultipleRequests() throws Exception { - connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616); + connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setHttpCompliance(HttpCompliance.RFC2616); // Verify that pipelining does not work with HTTP/0.9. String requests = "GET /?id=123\r\n\r\nGET /?id=456\r\n\r\n"; @@ -407,7 +407,7 @@ public class HttpConnectionTest @Test public void test_0_9() throws Exception { - connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616_LEGACY); + connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setHttpCompliance(HttpCompliance.RFC2616_LEGACY); LocalEndPoint endp = connector.executeRequest("GET /R1\n"); endp.waitUntilClosed(); String response=BufferUtil.toString(endp.takeOutput()); diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ComplianceViolations2616Test.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ComplianceViolations2616Test.java index f9b8d430310..e3ee9ecc916 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ComplianceViolations2616Test.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ComplianceViolations2616Test.java @@ -109,8 +109,9 @@ public class ComplianceViolations2616Test HttpConfiguration config = new HttpConfiguration(); config.setSendServerVersion(false); + config.setHttpCompliance(HttpCompliance.RFC2616_LEGACY); - HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(config, HttpCompliance.RFC2616_LEGACY); + HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(config); httpConnectionFactory.setRecordHttpComplianceViolations(true); connector = new LocalConnector(server, null, null, null, -1, httpConnectionFactory);