Merge pull request #3017 from eclipse/jetty-10.x-issue-3011-move-httpcompliance-to-config

Issue #3011 - Moving HttpCompliance to HttpConfiguration
This commit is contained in:
Joakim Erdfelt 2018-10-22 16:24:28 -05:00 committed by GitHub
commit 405a6b671d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 27 additions and 36 deletions

View File

@ -128,7 +128,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override @Override
public Connection newConnection(Connector connector, EndPoint endPoint) public Connection newConnection(Connector connector, EndPoint endPoint)
{ {
return configure(new HttpConnection(getHttpConfiguration(), connector, endPoint,getHttpCompliance(),isRecordHttpComplianceViolations()) return configure(new HttpConnection(getHttpConfiguration(), connector, endPoint, isRecordHttpComplianceViolations())
{ {
@Override @Override
protected HttpParser newHttpParser(HttpCompliance compliance) protected HttpParser newHttpParser(HttpCompliance compliance)

View File

@ -300,7 +300,7 @@ public class HTTP2CServerTest extends AbstractServerTest
@Override @Override
public Connection newConnection(Connector connector, EndPoint endPoint) public Connection newConnection(Connector connector, EndPoint endPoint)
{ {
HttpConnection connection = new HttpConnection(getHttpConfiguration(), connector, endPoint,getHttpCompliance(),isRecordHttpComplianceViolations()) HttpConnection connection = new HttpConnection(getHttpConfiguration(), connector, endPoint, isRecordHttpComplianceViolations())
{ {
@Override @Override
public void onFillable() public void onFillable()

View File

@ -24,6 +24,7 @@ import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jetty.http.CookieCompliance; import org.eclipse.jetty.http.CookieCompliance;
import org.eclipse.jetty.http.HttpCompliance;
import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.MultiPartFormDataCompliance; import org.eclipse.jetty.http.MultiPartFormDataCompliance;
@ -72,6 +73,7 @@ public class HttpConfiguration
private boolean _useDirectByteBuffers = false; private boolean _useDirectByteBuffers = false;
private long _minRequestDataRate; private long _minRequestDataRate;
private long _minResponseDataRate; private long _minResponseDataRate;
private HttpCompliance _httpCompliance = HttpCompliance.RFC7230;
private CookieCompliance _cookieCompliance = CookieCompliance.RFC6265; private CookieCompliance _cookieCompliance = CookieCompliance.RFC6265;
private MultiPartFormDataCompliance _multiPartCompliance = MultiPartFormDataCompliance.RFC7578; private MultiPartFormDataCompliance _multiPartCompliance = MultiPartFormDataCompliance.RFC7578;
private boolean _notifyRemoteAsyncErrors = true; private boolean _notifyRemoteAsyncErrors = true;
@ -548,6 +550,16 @@ public class HttpConfiguration
_minResponseDataRate = bytesPerSecond; _minResponseDataRate = bytesPerSecond;
} }
public HttpCompliance getHttpCompliance()
{
return _httpCompliance;
}
public void setHttpCompliance(HttpCompliance _httpCompliance)
{
this._httpCompliance = _httpCompliance;
}
public CookieCompliance getCookieCompliance() public CookieCompliance getCookieCompliance()
{ {
return _cookieCompliance; return _cookieCompliance;

View File

@ -93,7 +93,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
return last; return last;
} }
public HttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint, HttpCompliance compliance, boolean recordComplianceViolations) public HttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint, boolean recordComplianceViolations)
{ {
super(endPoint, connector.getExecutor()); super(endPoint, connector.getExecutor());
_config = config; _config = config;
@ -102,7 +102,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
_generator = newHttpGenerator(); _generator = newHttpGenerator();
_channel = newHttpChannel(); _channel = newHttpChannel();
_input = _channel.getRequest().getHttpInput(); _input = _channel.getRequest().getHttpInput();
_parser = newHttpParser(compliance); _parser = newHttpParser(config.getHttpCompliance());
_recordHttpComplianceViolations = recordComplianceViolations; _recordHttpComplianceViolations = recordComplianceViolations;
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("New HTTP Connection {}", this); LOG.debug("New HTTP Connection {}", this);

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import org.eclipse.jetty.http.HttpCompliance;
import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
@ -32,7 +31,6 @@ import org.eclipse.jetty.util.annotation.Name;
public class HttpConnectionFactory extends AbstractConnectionFactory implements HttpConfiguration.ConnectionFactory public class HttpConnectionFactory extends AbstractConnectionFactory implements HttpConfiguration.ConnectionFactory
{ {
private final HttpConfiguration _config; private final HttpConfiguration _config;
private HttpCompliance _httpCompliance;
private boolean _recordHttpComplianceViolations = false; private boolean _recordHttpComplianceViolations = false;
public HttpConnectionFactory() public HttpConnectionFactory()
@ -41,15 +39,9 @@ public class HttpConnectionFactory extends AbstractConnectionFactory implements
} }
public HttpConnectionFactory(@Name("config") HttpConfiguration config) 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()); super(HttpVersion.HTTP_1_1.asString());
_config=config; _config=config;
_httpCompliance=compliance==null?HttpCompliance.RFC7230:compliance;
if (config==null) if (config==null)
throw new IllegalArgumentException("Null HttpConfiguration"); throw new IllegalArgumentException("Null HttpConfiguration");
addBean(_config); addBean(_config);
@ -61,28 +53,15 @@ public class HttpConnectionFactory extends AbstractConnectionFactory implements
return _config; return _config;
} }
public HttpCompliance getHttpCompliance()
{
return _httpCompliance;
}
public boolean isRecordHttpComplianceViolations() public boolean isRecordHttpComplianceViolations()
{ {
return _recordHttpComplianceViolations; return _recordHttpComplianceViolations;
} }
/**
* @param httpCompliance String value of {@link HttpCompliance}
*/
public void setHttpCompliance(HttpCompliance httpCompliance)
{
_httpCompliance = httpCompliance;
}
@Override @Override
public Connection newConnection(Connector connector, EndPoint endPoint) public Connection newConnection(Connector connector, EndPoint endPoint)
{ {
HttpConnection conn = new HttpConnection(_config, connector, endPoint, _httpCompliance,isRecordHttpComplianceViolations()); HttpConnection conn = new HttpConnection(_config, connector, endPoint, isRecordHttpComplianceViolations());
return configure(conn, connector, endPoint); return configure(conn, connector, endPoint);
} }

View File

@ -33,7 +33,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpCompliance;
import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.ChannelEndPoint; import org.eclipse.jetty.io.ChannelEndPoint;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
@ -104,7 +103,7 @@ public class ExtendedServerTest extends HttpServerTestBase
{ {
public ExtendedHttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint) public ExtendedHttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint)
{ {
super(config,connector,endPoint,HttpCompliance.RFC7230_LEGACY,false); super(config,connector,endPoint, false);
} }
@Override @Override

View File

@ -281,7 +281,7 @@ public class GracefulStopTest
public Connection newConnection(Connector con, EndPoint endPoint) public Connection newConnection(Connector con, EndPoint endPoint)
{ {
// Slow closing connection // Slow closing connection
HttpConnection conn = new HttpConnection(getHttpConfiguration(), con, endPoint, getHttpCompliance(), isRecordHttpComplianceViolations()) HttpConnection conn = new HttpConnection(getHttpConfiguration(), con, endPoint, isRecordHttpComplianceViolations())
{ {
@Override @Override
public void close() public void close()

View File

@ -148,12 +148,12 @@ public class HttpConnectionTest
@Test @Test
public void testHttp09_NoVersion() throws Exception 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 request = "GET / HTTP/0.9\r\n\r\n";
String response = connector.getResponse(request); String response = connector.getResponse(request);
assertThat(response, containsString("400 Bad Version")); 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"; request = "GET / HTTP/0.9\r\n\r\n";
response = connector.getResponse(request); response = connector.getResponse(request);
assertThat(response, containsString("400 Bad Version")); assertThat(response, containsString("400 Bad Version"));
@ -165,7 +165,7 @@ public class HttpConnectionTest
@Test @Test
public void testHttp09_NoHeaders() throws Exception 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 // header looking like another request is ignored
String request = "GET /one\r\nGET :/two\r\n\r\n"; String request = "GET /one\r\nGET :/two\r\n\r\n";
String response = BufferUtil.toString(connector.executeRequest(request).waitForOutput(10,TimeUnit.SECONDS)); String response = BufferUtil.toString(connector.executeRequest(request).waitForOutput(10,TimeUnit.SECONDS));
@ -179,7 +179,7 @@ public class HttpConnectionTest
@Test @Test
public void testHttp09_MultipleRequests() throws Exception 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. // 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"; String requests = "GET /?id=123\r\n\r\nGET /?id=456\r\n\r\n";
@ -407,7 +407,7 @@ public class HttpConnectionTest
@Test @Test
public void test_0_9() throws Exception 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"); LocalEndPoint endp = connector.executeRequest("GET /R1\n");
endp.waitUntilClosed(); endp.waitUntilClosed();
String response=BufferUtil.toString(endp.takeOutput()); String response=BufferUtil.toString(endp.takeOutput());

View File

@ -57,7 +57,7 @@ public class SlowClientWithPipelinedRequestTest
@Override @Override
public Connection newConnection(Connector connector, EndPoint endPoint) public Connection newConnection(Connector connector, EndPoint endPoint)
{ {
return configure(new HttpConnection(getHttpConfiguration(),connector,endPoint,getHttpCompliance(),isRecordHttpComplianceViolations()) return configure(new HttpConnection(getHttpConfiguration(),connector,endPoint, isRecordHttpComplianceViolations())
{ {
@Override @Override
public void onFillable() public void onFillable()

View File

@ -109,8 +109,9 @@ public class ComplianceViolations2616Test
HttpConfiguration config = new HttpConfiguration(); HttpConfiguration config = new HttpConfiguration();
config.setSendServerVersion(false); config.setSendServerVersion(false);
config.setHttpCompliance(HttpCompliance.RFC2616_LEGACY);
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(config, HttpCompliance.RFC2616_LEGACY); HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(config);
httpConnectionFactory.setRecordHttpComplianceViolations(true); httpConnectionFactory.setRecordHttpComplianceViolations(true);
connector = new LocalConnector(server, null, null, null, -1, httpConnectionFactory); connector = new LocalConnector(server, null, null, null, -1, httpConnectionFactory);