Search in sources :

Example 6 with HttpVersionPolicy

use of org.apache.hc.core5.http2.HttpVersionPolicy in project httpcomponents-core by apache.

the class ServerHttpProtocolNegotiationStarter method createHandler.

@Override
public HttpConnectionEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    HttpVersionPolicy endpointPolicy = versionPolicy;
    URIScheme uriScheme = URIScheme.HTTP;
    if (attachment instanceof EndpointParameters) {
        final EndpointParameters params = (EndpointParameters) attachment;
        if (tlsStrategy != null && URIScheme.HTTPS.same(params.getScheme())) {
            uriScheme = URIScheme.HTTPS;
            tlsStrategy.upgrade(ioSession, params, params.getAttachment(), handshakeTimeout, null);
        }
        if (params.getAttachment() instanceof HttpVersionPolicy) {
            endpointPolicy = (HttpVersionPolicy) params.getAttachment();
        }
    }
    ioSession.registerProtocol(ApplicationProtocol.HTTP_1_1.id, new ServerHttp1UpgradeHandler(http1StreamHandlerFactory));
    ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ServerH2UpgradeHandler(http2StreamHandlerFactory));
    switch(endpointPolicy) {
        case FORCE_HTTP_2:
            return new ServerH2PrefaceHandler(ioSession, http2StreamHandlerFactory);
        case FORCE_HTTP_1:
            return new ServerHttp1IOEventHandler(http1StreamHandlerFactory.create(uriScheme.id, ioSession));
        default:
            return new HttpProtocolNegotiator(ioSession, null);
    }
}
Also used : HttpVersionPolicy(org.apache.hc.core5.http2.HttpVersionPolicy) URIScheme(org.apache.hc.core5.http.URIScheme) ServerHttp1IOEventHandler(org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler) EndpointParameters(org.apache.hc.core5.reactor.EndpointParameters)

Aggregations

HttpVersionPolicy (org.apache.hc.core5.http2.HttpVersionPolicy)3 InetSocketAddress (java.net.InetSocketAddress)2 ByteBuffer (java.nio.ByteBuffer)2 HttpRequest (org.apache.hc.core5.http.HttpRequest)2 EndpointParameters (org.apache.hc.core5.reactor.EndpointParameters)2 File (java.io.File)1 IOException (java.io.IOException)1 SocketAddress (java.net.SocketAddress)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ByteChannel (java.nio.channels.ByteChannel)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Lock (java.util.concurrent.locks.Lock)1 SSLContext (javax.net.ssl.SSLContext)1 EntityDetails (org.apache.hc.core5.http.EntityDetails)1 Header (org.apache.hc.core5.http.Header)1 HttpConnection (org.apache.hc.core5.http.HttpConnection)1 HttpResponse (org.apache.hc.core5.http.HttpResponse)1 HttpStreamResetException (org.apache.hc.core5.http.HttpStreamResetException)1 Message (org.apache.hc.core5.http.Message)1