Issue #3011 - Moving HttpCompliance to HttpConfiguration

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2018-10-22 13:10:05 -05:00
parent 6bbc26fab8
commit 4679565fd5
4 changed files with 21 additions and 23 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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());

View File

@ -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);