Search in sources :

Example 1 with EndpointParameters

use of org.apache.hc.core5.reactor.EndpointParameters in project httpcomponents-core by apache.

the class ClientHttpProtocolNegotiationStarter method createHandler.

@Override
public HttpConnectionEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    HttpVersionPolicy endpointPolicy = versionPolicy;
    if (attachment instanceof EndpointParameters) {
        final EndpointParameters params = (EndpointParameters) attachment;
        if (tlsStrategy != null && URIScheme.HTTPS.same(params.getScheme())) {
            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 ClientHttp1UpgradeHandler(http1StreamHandlerFactory));
    ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ClientH2UpgradeHandler(http2StreamHandlerFactory));
    switch(endpointPolicy) {
        case FORCE_HTTP_2:
            return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
        case FORCE_HTTP_1:
            return new ClientHttp1IOEventHandler(http1StreamHandlerFactory.create(ioSession));
        default:
            return new HttpProtocolNegotiator(ioSession, null);
    }
}
Also used : HttpVersionPolicy(org.apache.hc.core5.http2.HttpVersionPolicy) EndpointParameters(org.apache.hc.core5.reactor.EndpointParameters) ClientHttp1IOEventHandler(org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)

Example 2 with EndpointParameters

use of org.apache.hc.core5.reactor.EndpointParameters in project httpcomponents-core by apache.

the class ServerHttp1IOEventHandlerFactory method createHandler.

@Override
public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    String endpointScheme = URIScheme.HTTP.id;
    if (attachment instanceof EndpointParameters) {
        final EndpointParameters params = (EndpointParameters) attachment;
        endpointScheme = params.getScheme();
        if (tlsStrategy != null && URIScheme.HTTPS.same(endpointScheme)) {
            tlsStrategy.upgrade(ioSession, params, params.getAttachment(), handshakeTimeout, null);
        }
    } else {
        tlsStrategy.upgrade(ioSession, null, attachment, handshakeTimeout, null);
    }
    return new ServerHttp1IOEventHandler(streamDuplexerFactory.create(endpointScheme, ioSession));
}
Also used : EndpointParameters(org.apache.hc.core5.reactor.EndpointParameters)

Example 3 with EndpointParameters

use of org.apache.hc.core5.reactor.EndpointParameters in project httpcomponents-core by apache.

the class HttpAsyncServer method listen.

/**
 * @since 5.1
 */
public Future<ListenerEndpoint> listen(final SocketAddress address, final URIScheme scheme, final Object attachment, final FutureCallback<ListenerEndpoint> callback) {
    final InetSocketAddress inetSocketAddress = (InetSocketAddress) address;
    final EndpointParameters parameters = new EndpointParameters(scheme.id, canonicalName != null ? canonicalName : "localhost", inetSocketAddress.getPort(), attachment);
    return super.listen(address, parameters, callback);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EndpointParameters(org.apache.hc.core5.reactor.EndpointParameters)

Example 4 with EndpointParameters

use of org.apache.hc.core5.reactor.EndpointParameters 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

EndpointParameters (org.apache.hc.core5.reactor.EndpointParameters)4 HttpVersionPolicy (org.apache.hc.core5.http2.HttpVersionPolicy)2 InetSocketAddress (java.net.InetSocketAddress)1 URIScheme (org.apache.hc.core5.http.URIScheme)1 ClientHttp1IOEventHandler (org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)1 ServerHttp1IOEventHandler (org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler)1