You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/04/26 19:21:31 UTC
svn commit: r1792796 - in /httpcomponents/httpcore/trunk:
httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ httpcore5-...
Author: olegk
Date: Wed Apr 26 19:21:30 2017
New Revision: 1792796
URL: http://svn.apache.org/viewvc?rev=1792796&view=rev
Log:
Provide protocol scheme identifiers for server side connections and incoming HTTP/1.1 requests
Added:
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java (contents, props changed)
- copied, changed from r1792795, httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/ProtocolScheme.java
Removed:
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/ProtocolScheme.java
Modified:
httpcomponents/httpcore/trunk/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java
Modified: httpcomponents/httpcore/trunk/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java Wed Apr 26 19:21:30 2017
@@ -82,7 +82,7 @@ public class HttpServer {
private HttpServerConnection acceptConnection() throws IOException {
final Socket socket = this.serversocket.accept();
- final DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(H1Config.DEFAULT);
+ final DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(null, H1Config.DEFAULT);
conn.bind(socket);
return conn;
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java Wed Apr 26 19:21:30 2017
@@ -38,6 +38,7 @@ import org.apache.hc.core5.annotation.Co
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.EndpointDetails;
import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.impl.ConnectionListener;
import org.apache.hc.core5.http.impl.nio.HttpConnectionEventHandler;
import org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler;
@@ -87,9 +88,9 @@ public class ServerHttpProtocolNegotiato
@Override
public void connected(final IOSession session) {
try {
+ final TlsDetails tlsDetails = ioSession.getTlsDetails();
switch (versionPolicy) {
case NEGOTIATE:
- final TlsDetails tlsDetails = ioSession.getTlsDetails();
if (tlsDetails != null) {
if (ApplicationProtocols.HTTP_2.id.equals(tlsDetails.getApplicationProtocol())) {
expectValidH2Preface = true;
@@ -99,7 +100,9 @@ public class ServerHttpProtocolNegotiato
}
break;
case FORCE_HTTP_1:
- final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(ioSession);
+ final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(
+ tlsDetails != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+ ioSession);
session.setHandler(new ServerHttp1IOEventHandler(http1StreamHandler));
http1StreamHandler.onConnect(null);
break;
@@ -134,7 +137,10 @@ public class ServerHttpProtocolNegotiato
http2StreamHandler.onConnect(bytebuf.hasRemaining() ? bytebuf : null);
http2StreamHandler.onInput();
} else {
- final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(ioSession);
+ final TlsDetails tlsDetails = ioSession.getTlsDetails();
+ final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(
+ tlsDetails != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+ ioSession);
session.setHandler(new ServerHttp1IOEventHandler(http1StreamHandler));
bytebuf.rewind();
http1StreamHandler.onConnect(bytebuf);
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java Wed Apr 26 19:21:30 2017
@@ -32,6 +32,7 @@ import java.net.SocketAddress;
import javax.net.ssl.SSLContext;
import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
@@ -86,18 +87,20 @@ public class H2ClientTlsStrategy impleme
}
@Override
- public void upgrade(
+ public boolean upgrade(
final TransportSecurityLayer tlsSession,
final HttpHost host,
final SocketAddress localAddress,
final SocketAddress remoteAddress,
final Object attachment) {
final String scheme = host != null ? host.getSchemeName() : null;
- if ("https".equalsIgnoreCase(scheme)) {
+ if (URIScheme.HTTPS.same(scheme)) {
tlsSession.startTls(sslContext, sslBufferManagement,
H2TlsSupport.enforceRequirements(attachment, initializer),
verifier);
+ return true;
}
+ return false;
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java Wed Apr 26 19:21:30 2017
@@ -91,7 +91,7 @@ public class H2ServerTlsStrategy impleme
}
@Override
- public void upgrade(
+ public boolean upgrade(
final TransportSecurityLayer tlsSession,
final HttpHost host,
final SocketAddress localAddress,
@@ -101,7 +101,9 @@ public class H2ServerTlsStrategy impleme
tlsSession.startTls(sslContext, sslBufferManagement,
H2TlsSupport.enforceRequirements(attachment, initializer),
verifier);
+ return true;
}
+ return false;
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java Wed Apr 26 19:21:30 2017
@@ -34,9 +34,11 @@ import java.net.SocketException;
import java.util.concurrent.atomic.AtomicReference;
import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
import org.apache.hc.core5.http.ConnectionClosedException;
import org.apache.hc.core5.http.ExceptionListener;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.config.SocketConfig;
import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
@@ -131,11 +133,13 @@ public class ClassicTestServer {
}
}
- class LoggingConnFactory implements HttpConnectionFactory<LoggingBHttpServerConnection> {
+ static class LoggingConnFactory implements HttpConnectionFactory<LoggingBHttpServerConnection> {
@Override
public LoggingBHttpServerConnection createConnection(final Socket socket) throws IOException {
- final LoggingBHttpServerConnection conn = new LoggingBHttpServerConnection(H1Config.DEFAULT);
+ final LoggingBHttpServerConnection conn = new LoggingBHttpServerConnection(
+ socket instanceof SSLSocket ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+ H1Config.DEFAULT);
conn.bind(socket);
return conn;
}
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java Wed Apr 26 19:21:30 2017
@@ -58,6 +58,7 @@ public class LoggingBHttpServerConnectio
private final Wire wire;
public LoggingBHttpServerConnection(
+ final String scheme,
final H1Config h1Config,
final CharsetDecoder chardecoder,
final CharsetEncoder charencoder,
@@ -65,7 +66,7 @@ public class LoggingBHttpServerConnectio
final ContentLengthStrategy outgoingContentStrategy,
final HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory,
final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
- super(h1Config, chardecoder, charencoder,
+ super(scheme, h1Config, chardecoder, charencoder,
incomingContentStrategy, outgoingContentStrategy,
requestParserFactory, responseWriterFactory);
this.id = "http-incoming-" + COUNT.incrementAndGet();
@@ -79,8 +80,8 @@ public class LoggingBHttpServerConnectio
return id;
}
- public LoggingBHttpServerConnection(final H1Config h1Config) {
- this(h1Config, null, null, null, null, null, null);
+ public LoggingBHttpServerConnection(final String scheme, final H1Config h1Config) {
+ this(scheme, h1Config, null, null, null, null, null, null);
}
@Override
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java Wed Apr 26 19:21:30 2017
@@ -35,6 +35,7 @@ import java.util.concurrent.ThreadFactor
import org.apache.hc.core5.concurrent.DefaultThreadFactory;
import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.net.NamedEndpoint;
import org.apache.hc.core5.reactor.ConnectionInitiator;
import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
@@ -68,9 +69,9 @@ public class AsyncRequester extends IORe
int port = host.getPort();
if (port < 0) {
final String scheme = host.getSchemeName();
- if ("http".equalsIgnoreCase(scheme)) {
+ if (URIScheme.HTTP.same(scheme)) {
port = 80;
- } else if ("https".equalsIgnoreCase(scheme)) {
+ } else if (URIScheme.HTTPS.same(scheme)) {
port = 443;
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java Wed Apr 26 19:21:30 2017
@@ -35,6 +35,7 @@ import org.apache.hc.core5.http.Connecti
import org.apache.hc.core5.http.ContentLengthStrategy;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.config.CharCodingConfig;
import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.impl.ConnectionListener;
@@ -105,7 +106,8 @@ class InternalServerHttp1EventHandlerFac
final ContentLengthStrategy outgoingContentStrategy,
final ConnectionListener connectionListener,
final Http1StreamListener streamListener) {
- return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory, h1Config,
+ return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory,
+ sslContext != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id, h1Config,
charCodingConfig, connectionReuseStrategy, incomingMessageParser, outgoingMessageWriter,
incomingContentStrategy, outgoingContentStrategy, connectionListener, streamListener);
}
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java Wed Apr 26 19:21:30 2017
@@ -75,6 +75,7 @@ import org.apache.hc.core5.http.HttpVers
import org.apache.hc.core5.http.MalformedChunkCodingException;
import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.config.CharCodingConfig;
import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
@@ -124,7 +125,6 @@ import org.apache.hc.core5.reactor.IORea
import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.reactor.SessionRequest;
import org.apache.hc.core5.reactor.TlsCapableIOSession;
-import org.apache.hc.core5.testing.ProtocolScheme;
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.util.CharArrayBuffer;
import org.apache.hc.core5.util.TextUtils;
@@ -142,12 +142,12 @@ public class Http1IntegrationTest extend
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> protocols() {
return Arrays.asList(new Object[][]{
- { ProtocolScheme.HTTP },
- { ProtocolScheme.HTTPS }
+ { URIScheme.HTTP },
+ { URIScheme.HTTPS }
});
}
- public Http1IntegrationTest(final ProtocolScheme scheme) {
+ public Http1IntegrationTest(final URIScheme scheme) {
super(scheme);
}
@@ -160,7 +160,7 @@ public class Http1IntegrationTest extend
public void setup() throws Exception {
client = new Http1TestClient(
IOReactorConfig.DEFAULT,
- scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
+ scheme == URIScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
}
@After
@@ -172,7 +172,7 @@ public class Http1IntegrationTest extend
private URI createRequestURI(final InetSocketAddress serverEndpoint, final String path) {
try {
- return new URI("http", null, "localhost", serverEndpoint.getPort(), path, null, null);
+ return new URI(scheme.id, null, "localhost", serverEndpoint.getPort(), path, null, null);
} catch (final URISyntaxException e) {
throw new IllegalStateException();
}
@@ -1357,7 +1357,7 @@ public class Http1IntegrationTest extend
H1Config.DEFAULT,
CharCodingConfig.DEFAULT,
DefaultConnectionReuseStrategy.INSTANCE,
- scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null) {
+ scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null) {
@Override
protected ServerHttp1StreamDuplexer createServerHttp1StreamDuplexer(
@@ -1374,6 +1374,7 @@ public class Http1IntegrationTest extend
final ConnectionListener connectionListener,
final Http1StreamListener streamListener) {
return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory,
+ scheme.id,
h1Config, connectionConfig, connectionReuseStrategy,
incomingMessageParser, outgoingMessageWriter,
incomingContentStrategy, outgoingContentStrategy,
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java Wed Apr 26 19:21:30 2017
@@ -76,6 +76,7 @@ import org.apache.hc.core5.http.HttpResp
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.impl.nio.AbstractClassicServerExchangeHandler;
import org.apache.hc.core5.http.impl.nio.entity.AbstractClassicEntityConsumer;
import org.apache.hc.core5.http.impl.nio.entity.AbstractClassicEntityProducer;
@@ -110,7 +111,6 @@ import org.apache.hc.core5.http2.nio.sup
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.reactor.SessionRequest;
-import org.apache.hc.core5.testing.ProtocolScheme;
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.util.TextUtils;
import org.apache.hc.core5.util.TimeValue;
@@ -128,12 +128,12 @@ public class Http2IntegrationTest extend
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> protocols() {
return Arrays.asList(new Object[][]{
- { ProtocolScheme.HTTP },
- { ProtocolScheme.HTTPS }
+ { URIScheme.HTTP },
+ { URIScheme.HTTPS }
});
}
- public Http2IntegrationTest(final ProtocolScheme scheme) {
+ public Http2IntegrationTest(final URIScheme scheme) {
super(scheme);
}
@@ -145,7 +145,7 @@ public class Http2IntegrationTest extend
@Before
public void setup() throws Exception {
client = new Http2TestClient(IOReactorConfig.DEFAULT,
- scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
+ scheme == URIScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
}
@After
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java Wed Apr 26 19:21:30 2017
@@ -27,8 +27,8 @@
package org.apache.hc.core5.testing.nio;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.reactor.IOReactorConfig;
-import org.apache.hc.core5.testing.ProtocolScheme;
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.util.TimeValue;
import org.junit.Rule;
@@ -36,14 +36,14 @@ import org.junit.rules.ExternalResource;
public abstract class InternalHttp1ServerTestBase {
- protected final ProtocolScheme scheme;
+ protected final URIScheme scheme;
- public InternalHttp1ServerTestBase(final ProtocolScheme scheme) {
+ public InternalHttp1ServerTestBase(final URIScheme scheme) {
this.scheme = scheme;
}
public InternalHttp1ServerTestBase() {
- this(ProtocolScheme.HTTP);
+ this(URIScheme.HTTP);
}
protected Http1TestServer server;
@@ -55,7 +55,7 @@ public abstract class InternalHttp1Serve
protected void before() throws Throwable {
server = new Http1TestServer(
IOReactorConfig.DEFAULT,
- scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
+ scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
}
@Override
Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java Wed Apr 26 19:21:30 2017
@@ -27,8 +27,8 @@
package org.apache.hc.core5.testing.nio;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.reactor.IOReactorConfig;
-import org.apache.hc.core5.testing.ProtocolScheme;
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.util.TimeValue;
import org.junit.Rule;
@@ -36,14 +36,14 @@ import org.junit.rules.ExternalResource;
public abstract class InternalHttp2ServerTestBase {
- protected final ProtocolScheme scheme;
+ protected final URIScheme scheme;
- public InternalHttp2ServerTestBase(final ProtocolScheme scheme) {
+ public InternalHttp2ServerTestBase(final URIScheme scheme) {
this.scheme = scheme;
}
public InternalHttp2ServerTestBase() {
- this(ProtocolScheme.HTTP);
+ this(URIScheme.HTTP);
}
protected Http2TestServer server;
@@ -54,7 +54,7 @@ public abstract class InternalHttp2Serve
@Override
protected void before() throws Throwable {
server = new Http2TestServer(IOReactorConfig.DEFAULT,
- scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
+ scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
}
@Override
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java (from r1792795, httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/ProtocolScheme.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java&p1=httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/ProtocolScheme.java&r1=1792795&r2=1792796&rev=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/ProtocolScheme.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java Wed Apr 26 19:21:30 2017
@@ -25,6 +25,27 @@
*
*/
-package org.apache.hc.core5.testing;
+package org.apache.hc.core5.http;
-public enum ProtocolScheme { HTTP, HTTPS }
+import org.apache.hc.core5.util.Args;
+
+public enum URIScheme {
+
+ HTTP("http"), HTTPS("https");
+
+ public final String id;
+
+ URIScheme(final String id) {
+ this.id = Args.notBlank(id, "Id");
+ }
+
+ public boolean same(final String scheme) {
+ return id.equalsIgnoreCase(scheme);
+ }
+
+ @Override
+ public String toString() {
+ return id;
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java Wed Apr 26 19:21:30 2017
@@ -34,6 +34,7 @@ import org.apache.hc.core5.concurrent.De
import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.http.ExceptionListener;
import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.net.NamedEndpoint;
import org.apache.hc.core5.reactor.ConnectionInitiator;
import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
@@ -63,9 +64,9 @@ public class AsyncRequester extends IORe
int port = host.getPort();
if (port < 0) {
final String scheme = host.getSchemeName();
- if ("http".equalsIgnoreCase(scheme)) {
+ if (URIScheme.HTTP.same(scheme)) {
port = 80;
- } else if ("https".equalsIgnoreCase(scheme)) {
+ } else if (URIScheme.HTTPS.same(scheme)) {
port = 443;
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java Wed Apr 26 19:21:30 2017
@@ -46,6 +46,7 @@ import org.apache.hc.core5.http.HttpHost
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
import org.apache.hc.core5.http.nio.AsyncRequestProducer;
@@ -137,7 +138,7 @@ public class HttpAsyncRequester extends
@Override
public void completed(final SessionRequest request) {
final TlsCapableIOSession session = request.getSession();
- if (tlsStrategy != null && "https".equalsIgnoreCase(host.getSchemeName())) {
+ if (tlsStrategy != null && URIScheme.HTTPS.same(host.getSchemeName())) {
tlsStrategy.upgrade(
session,
host,
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java Wed Apr 26 19:21:30 2017
@@ -46,6 +46,9 @@ import org.apache.hc.core5.http.Connecti
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.config.SocketConfig;
import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnectionFactory;
import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
@@ -89,7 +92,8 @@ public class HttpRequester implements Gr
this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
this.connPool = Args.notNull(connPool, "Connection pool");
this.socketConfig = socketConfig != null ? socketConfig : SocketConfig.DEFAULT;
- this.connectFactory = connectFactory != null ? connectFactory : DefaultBHttpClientConnectionFactory.INSTANCE;
+ this.connectFactory = connectFactory != null ? connectFactory : new DefaultBHttpClientConnectionFactory(
+ H1Config.DEFAULT, CharCodingConfig.DEFAULT);
this.sslSocketFactory = sslSocketFactory != null ? sslSocketFactory : (SSLSocketFactory) SSLSocketFactory.getDefault();
}
@@ -160,9 +164,9 @@ public class HttpRequester implements Gr
final String scheme = targetHost.getSchemeName();
int port = targetHost.getPort();
if (port < 0) {
- if ("http".equalsIgnoreCase(scheme)) {
+ if (URIScheme.HTTP.same(scheme)) {
port = 80;
- } else if ("https".equalsIgnoreCase(scheme)) {
+ } else if (URIScheme.HTTPS.same(scheme)) {
port = 443;
}
}
@@ -174,7 +178,7 @@ public class HttpRequester implements Gr
}
sock.connect(targetAddress, socketConfig.getSoTimeout().toMillisIntBound());
- if ("https".equalsIgnoreCase(scheme)) {
+ if (URIScheme.HTTPS.same(scheme)) {
return sslSocketFactory.createSocket(sock, targetHost.getHostName(), port, true);
} else {
return sock;
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java Wed Apr 26 19:21:30 2017
@@ -37,9 +37,13 @@ import java.util.concurrent.atomic.Atomi
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
import org.apache.hc.core5.concurrent.DefaultThreadFactory;
import org.apache.hc.core5.http.ExceptionListener;
+import org.apache.hc.core5.http.URIScheme;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.config.SocketConfig;
import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection;
import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnectionFactory;
@@ -88,7 +92,10 @@ public class HttpServer implements Grace
this.ifAddress = ifAddress;
this.socketConfig = socketConfig != null ? socketConfig : SocketConfig.DEFAULT;
this.serverSocketFactory = serverSocketFactory != null ? serverSocketFactory : ServerSocketFactory.getDefault();
- this.connectionFactory = connectionFactory != null ? connectionFactory : DefaultBHttpServerConnectionFactory.INSTANCE;
+ this.connectionFactory = connectionFactory != null ? connectionFactory : new DefaultBHttpServerConnectionFactory(
+ this.serverSocketFactory instanceof SSLServerSocketFactory ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+ H1Config.DEFAULT,
+ CharCodingConfig.DEFAULT);
this.sslSetupHandler = sslSetupHandler;
this.exceptionListener = exceptionListener;
this.listenerExecutorService = new ThreadPoolExecutor(
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java Wed Apr 26 19:21:30 2017
@@ -30,6 +30,8 @@ import javax.net.ssl.SSLSocketFactory;
import org.apache.hc.core5.http.ConnectionReuseStrategy;
import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.config.SocketConfig;
import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
import org.apache.hc.core5.http.impl.Http1StreamListener;
@@ -148,7 +150,8 @@ public class RequesterBootstrap {
httpProcessor != null ? httpProcessor : HttpProcessors.client(),
connPool,
socketConfig != null ? socketConfig : SocketConfig.DEFAULT,
- connectFactory != null ? connectFactory : DefaultBHttpClientConnectionFactory.INSTANCE,
+ connectFactory != null ? connectFactory : new DefaultBHttpClientConnectionFactory(
+ H1Config.DEFAULT, CharCodingConfig.DEFAULT),
sslSocketFactory);
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java Wed Apr 26 19:21:30 2017
@@ -32,12 +32,15 @@ import java.util.Map;
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLServerSocketFactory;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ConnectionReuseStrategy;
import org.apache.hc.core5.http.ExceptionListener;
import org.apache.hc.core5.http.HttpResponseFactory;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.config.SocketConfig;
import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
import org.apache.hc.core5.http.impl.Http1StreamListener;
@@ -61,6 +64,7 @@ public class ServerBootstrap {
private int listenerPort;
private InetAddress localAddress;
private SocketConfig socketConfig;
+ private H1Config h1Config;
private CharCodingConfig charCodingConfig;
private HttpProcessor httpProcessor;
private ConnectionReuseStrategy connStrategy;
@@ -108,9 +112,14 @@ public class ServerBootstrap {
/**
* Sets connection configuration.
- * <p>
- * Please note this value can be overridden by the {@link #setConnectionFactory(
- *HttpConnectionFactory)} method.
+ */
+ public final ServerBootstrap setH1Config(final H1Config h1Config) {
+ this.h1Config = h1Config;
+ return this;
+ }
+
+ /**
+ * Sets connection configuration.
*/
public final ServerBootstrap setCharCodingConfig(final CharCodingConfig charCodingConfig) {
this.charCodingConfig = charCodingConfig;
@@ -273,11 +282,8 @@ public class ServerBootstrap {
HttpConnectionFactory<? extends DefaultBHttpServerConnection> connectionFactoryCopy = this.connectionFactory;
if (connectionFactoryCopy == null) {
- if (this.charCodingConfig != null) {
- connectionFactoryCopy = new DefaultBHttpServerConnectionFactory(this.charCodingConfig);
- } else {
- connectionFactoryCopy = DefaultBHttpServerConnectionFactory.INSTANCE;
- }
+ final String scheme = serverSocketFactoryCopy instanceof SSLServerSocketFactory ? URIScheme.HTTPS.id : URIScheme.HTTP.id;
+ connectionFactoryCopy = new DefaultBHttpServerConnectionFactory(scheme, this.h1Config, this.charCodingConfig);
}
ExceptionListener exceptionListenerCopy = this.exceptionListener;
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java Wed Apr 26 19:21:30 2017
@@ -36,8 +36,8 @@ import org.apache.hc.core5.http.ClassicH
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentLengthStrategy;
import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.impl.CharCodingSupport;
import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.CharCodingSupport;
import org.apache.hc.core5.http.io.HttpConnectionFactory;
import org.apache.hc.core5.http.io.HttpMessageParserFactory;
import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
@@ -51,8 +51,6 @@ import org.apache.hc.core5.http.io.HttpM
public class DefaultBHttpClientConnectionFactory
implements HttpConnectionFactory<DefaultBHttpClientConnection> {
- public static final DefaultBHttpClientConnectionFactory INSTANCE = new DefaultBHttpClientConnectionFactory();
-
private final H1Config h1Config;
private final CharCodingConfig charCodingConfig;
private final ContentLengthStrategy incomingContentStrategy;
@@ -78,14 +76,16 @@ public class DefaultBHttpClientConnectio
public DefaultBHttpClientConnectionFactory(
final H1Config h1Config,
- final CharCodingConfig cconfig,
+ final CharCodingConfig charCodingConfig,
final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
- this(h1Config, cconfig, null, null, requestWriterFactory, responseParserFactory);
+ this(h1Config, charCodingConfig, null, null, requestWriterFactory, responseParserFactory);
}
- public DefaultBHttpClientConnectionFactory(final CharCodingConfig cconfig) {
- this(null, cconfig, null, null, null, null);
+ public DefaultBHttpClientConnectionFactory(
+ final H1Config h1Config,
+ final CharCodingConfig charCodingConfig) {
+ this(h1Config, charCodingConfig, null, null, null, null);
}
public DefaultBHttpClientConnectionFactory() {
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java Wed Apr 26 19:21:30 2017
@@ -58,6 +58,7 @@ import org.apache.hc.core5.util.Args;
*/
public class DefaultBHttpServerConnection extends BHttpConnectionBase implements HttpServerConnection {
+ private final String scheme;
private final ContentLengthStrategy incomingContentStrategy;
private final ContentLengthStrategy outgoingContentStrategy;
private final HttpMessageParser<ClassicHttpRequest> requestParser;
@@ -66,6 +67,7 @@ public class DefaultBHttpServerConnectio
/**
* Creates new instance of DefaultBHttpServerConnection.
*
+ * @param scheme protocol scheme
* @param h1Config Message h1Config. If {@code null}
* {@link H1Config#DEFAULT} will be used.
* @param chardecoder decoder to be used for decoding HTTP protocol elements.
@@ -82,6 +84,7 @@ public class DefaultBHttpServerConnectio
* {@link DefaultHttpResponseWriterFactory#INSTANCE} will be used.
*/
public DefaultBHttpServerConnection(
+ final String scheme,
final H1Config h1Config,
final CharsetDecoder chardecoder,
final CharsetEncoder charencoder,
@@ -90,6 +93,7 @@ public class DefaultBHttpServerConnectio
final HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory,
final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
super(h1Config, chardecoder, charencoder);
+ this.scheme = scheme;
this.requestParser = (requestParserFactory != null ? requestParserFactory :
DefaultHttpRequestParserFactory.INSTANCE).create(h1Config);
this.responseWriter = (responseWriterFactory != null ? responseWriterFactory :
@@ -101,14 +105,17 @@ public class DefaultBHttpServerConnectio
}
public DefaultBHttpServerConnection(
+ final String scheme,
final H1Config h1Config,
final CharsetDecoder chardecoder,
final CharsetEncoder charencoder) {
- this(h1Config, chardecoder, charencoder, null, null, null, null);
+ this(scheme, h1Config, chardecoder, charencoder, null, null, null, null);
}
- public DefaultBHttpServerConnection(final H1Config h1Config) {
- this(h1Config, null, null);
+ public DefaultBHttpServerConnection(
+ final String scheme,
+ final H1Config h1Config) {
+ this(scheme, h1Config, null, null);
}
protected void onRequestReceived(final ClassicHttpRequest request) {
@@ -130,6 +137,7 @@ public class DefaultBHttpServerConnectio
if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
throw new UnsupportedHttpVersionException("Unsupported version: " + transportVersion);
}
+ request.setScheme(this.scheme);
this.version = transportVersion;
onRequestReceived(request);
incrementRequestCount();
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java Wed Apr 26 19:21:30 2017
@@ -36,8 +36,8 @@ import org.apache.hc.core5.http.ClassicH
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentLengthStrategy;
import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.impl.CharCodingSupport;
import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.CharCodingSupport;
import org.apache.hc.core5.http.io.HttpConnectionFactory;
import org.apache.hc.core5.http.io.HttpMessageParserFactory;
import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
@@ -48,11 +48,9 @@ import org.apache.hc.core5.http.io.HttpM
* @since 4.3
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
-public class DefaultBHttpServerConnectionFactory
- implements HttpConnectionFactory<DefaultBHttpServerConnection> {
-
- public static final DefaultBHttpServerConnectionFactory INSTANCE = new DefaultBHttpServerConnectionFactory();
+public class DefaultBHttpServerConnectionFactory implements HttpConnectionFactory<DefaultBHttpServerConnection> {
+ private final String scheme;
private final H1Config h1Config;
private final CharCodingConfig charCodingConfig;
private final ContentLengthStrategy incomingContentStrategy;
@@ -61,6 +59,7 @@ public class DefaultBHttpServerConnectio
private final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory;
public DefaultBHttpServerConnectionFactory(
+ final String scheme,
final H1Config h1Config,
final CharCodingConfig charCodingConfig,
final ContentLengthStrategy incomingContentStrategy,
@@ -68,6 +67,7 @@ public class DefaultBHttpServerConnectio
final HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory,
final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
super();
+ this.scheme = scheme;
this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
this.incomingContentStrategy = incomingContentStrategy;
@@ -77,24 +77,25 @@ public class DefaultBHttpServerConnectio
}
public DefaultBHttpServerConnectionFactory(
+ final String scheme,
final H1Config h1Config,
final CharCodingConfig charCodingConfig,
final HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory,
final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
- this(h1Config, charCodingConfig, null, null, requestParserFactory, responseWriterFactory);
+ this(scheme, h1Config, charCodingConfig, null, null, requestParserFactory, responseWriterFactory);
}
- public DefaultBHttpServerConnectionFactory(final CharCodingConfig charCodingConfig) {
- this(null, charCodingConfig, null, null, null, null);
- }
-
- public DefaultBHttpServerConnectionFactory() {
- this(null, null, null, null, null, null);
+ public DefaultBHttpServerConnectionFactory(
+ final String scheme,
+ final H1Config h1Config,
+ final CharCodingConfig charCodingConfig) {
+ this(scheme, h1Config, charCodingConfig, null, null, null, null);
}
@Override
public DefaultBHttpServerConnection createConnection(final Socket socket) throws IOException {
final DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(
+ this.scheme,
this.h1Config,
CharCodingSupport.createDecoder(this.charCodingConfig),
CharCodingSupport.createEncoder(this.charCodingConfig),
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java Wed Apr 26 19:21:30 2017
@@ -29,6 +29,7 @@ package org.apache.hc.core5.http.impl.ni
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
import org.apache.hc.core5.reactor.IOEventHandler;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -53,15 +54,20 @@ public class ServerHttp1IOEventHandlerFa
@Override
public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
+ final boolean tlsSecured;
if (tlsStrategy != null) {
- tlsStrategy.upgrade(
+ tlsSecured = tlsStrategy.upgrade(
ioSession,
null,
ioSession.getLocalAddress(),
ioSession.getRemoteAddress(),
attachment);
+ } else {
+ tlsSecured = false;
}
- return new ServerHttp1IOEventHandler(streamDuplexerFactory.create(ioSession));
+ return new ServerHttp1IOEventHandler(streamDuplexerFactory.create(
+ tlsSecured ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+ ioSession));
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java Wed Apr 26 19:21:30 2017
@@ -69,6 +69,7 @@ import org.apache.hc.core5.util.Asserts;
public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpRequest, HttpResponse> {
+ private final String scheme;
private final HttpProcessor httpProcessor;
private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
private final H1Config h1Config;
@@ -86,6 +87,7 @@ public class ServerHttp1StreamDuplexer e
final TlsCapableIOSession ioSession,
final HttpProcessor httpProcessor,
final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+ final String scheme,
final H1Config h1Config,
final CharCodingConfig charCodingConfig,
final ConnectionReuseStrategy connectionReuseStrategy,
@@ -98,6 +100,7 @@ public class ServerHttp1StreamDuplexer e
super(ioSession, h1Config, charCodingConfig, incomingMessageParser, outgoingMessageWriter, connectionListener);
this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
+ this.scheme = scheme;
this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
this.connectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy :
DefaultConnectionReuseStrategy.INSTANCE;
@@ -321,6 +324,7 @@ public class ServerHttp1StreamDuplexer e
context);
pipeline.add(streamHandler);
}
+ request.setScheme(scheme);
streamHandler.consumeHeader(request, endStream);
incoming = streamHandler;
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java Wed Apr 26 19:21:30 2017
@@ -120,8 +120,9 @@ public final class ServerHttp1StreamDupl
this(httpProcessor, exchangeHandlerFactory, h1Config, charCodingConfig, null, null ,null, connectionListener, streamListener);
}
- public ServerHttp1StreamDuplexer create(final TlsCapableIOSession ioSession) {
+ public ServerHttp1StreamDuplexer create(final String scheme, final TlsCapableIOSession ioSession) {
return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory,
+ scheme,
h1Config,
charCodingConfig,
connectionReuseStrategy,
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java Wed Apr 26 19:21:30 2017
@@ -32,6 +32,7 @@ import java.net.SocketAddress;
import javax.net.ssl.SSLContext;
import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
@@ -85,16 +86,18 @@ public class BasicClientTlsStrategy impl
}
@Override
- public void upgrade(
+ public boolean upgrade(
final TransportSecurityLayer tlsSession,
final HttpHost host,
final SocketAddress localAddress,
final SocketAddress remoteAddress,
final Object attachment) {
final String scheme = host != null ? host.getSchemeName() : null;
- if ("https".equalsIgnoreCase(scheme)) {
+ if (URIScheme.HTTPS.same(scheme)) {
tlsSession.startTls(sslContext, sslBufferManagement, initializer, verifier);
+ return true;
}
+ return false;
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java Wed Apr 26 19:21:30 2017
@@ -91,7 +91,7 @@ public class BasicServerTlsStrategy impl
}
@Override
- public void upgrade(
+ public boolean upgrade(
final TransportSecurityLayer tlsSession,
final HttpHost host,
final SocketAddress localAddress,
@@ -101,9 +101,10 @@ public class BasicServerTlsStrategy impl
for (final int securePort: securePorts) {
if (port == securePort) {
tlsSession.startTls(sslContext, sslBufferManagement, initializer, verifier);
- break;
+ return true;
}
}
+ return false;
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java Wed Apr 26 19:21:30 2017
@@ -39,7 +39,7 @@ import org.apache.hc.core5.reactor.ssl.T
*/
public interface TlsStrategy {
- void upgrade(
+ boolean upgrade(
TransportSecurityLayer tlsSession,
HttpHost host,
SocketAddress localAddress,
Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java?rev=1792796&r1=1792795&r2=1792796&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java Wed Apr 26 19:21:30 2017
@@ -59,7 +59,7 @@ public class TestDefaultBHttpServerConne
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- conn = new DefaultBHttpServerConnection(H1Config.DEFAULT,
+ conn = new DefaultBHttpServerConnection("http", H1Config.DEFAULT,
null, null,
DefaultContentLengthStrategy.INSTANCE,
DefaultContentLengthStrategy.INSTANCE,