Search in sources :

Example 1 with TlsDetails

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

the class ClientH2PrefaceHandler method initialize.

private void initialize() throws IOException {
    final TlsDetails tlsDetails = ioSession.getTlsDetails();
    if (tlsDetails != null) {
        final String applicationProtocol = tlsDetails.getApplicationProtocol();
        if (TextUtils.isEmpty(applicationProtocol)) {
            if (strictALPNHandshake) {
                throw new ProtocolNegotiationException("ALPN: missing application protocol");
            }
        } else {
            if (!ApplicationProtocol.HTTP_2.id.equals(applicationProtocol)) {
                throw new ProtocolNegotiationException("ALPN: unexpected application protocol '" + applicationProtocol + "'");
            }
        }
    }
    this.preface = ByteBuffer.wrap(PREFACE);
    ioSession.setEvent(SelectionKey.OP_WRITE);
}
Also used : TlsDetails(org.apache.hc.core5.reactor.ssl.TlsDetails)

Example 2 with TlsDetails

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

the class ServerHttp1UpgradeHandler method upgrade.

@Override
public void upgrade(final ProtocolIOSession ioSession, final FutureCallback<ProtocolIOSession> callback) {
    final TlsDetails tlsDetails = ioSession.getTlsDetails();
    final ServerHttp1IOEventHandler eventHandler = new ServerHttp1IOEventHandler(http1StreamHandlerFactory.create(tlsDetails != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id, ioSession));
    ioSession.upgrade(eventHandler);
    ioSession.upgrade(eventHandler);
    try {
        eventHandler.connected(ioSession);
        if (callback != null) {
            callback.completed(ioSession);
        }
    } catch (final IOException ex) {
        eventHandler.exception(ioSession, ex);
    }
}
Also used : TlsDetails(org.apache.hc.core5.reactor.ssl.TlsDetails) IOException(java.io.IOException) ServerHttp1IOEventHandler(org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler)

Example 3 with TlsDetails

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

the class HttpProtocolNegotiator method connected.

@Override
public void connected(final IOSession session) throws IOException {
    final HttpVersion httpVersion;
    final TlsDetails tlsDetails = ioSession.getTlsDetails();
    if (tlsDetails != null) {
        final String appProtocol = tlsDetails.getApplicationProtocol();
        if (TextUtils.isEmpty(appProtocol)) {
            httpVersion = HttpVersion.HTTP_1_1;
        } else if (appProtocol.equals(ApplicationProtocol.HTTP_1_1.id)) {
            httpVersion = HttpVersion.HTTP_1_1;
        } else if (appProtocol.equals(ApplicationProtocol.HTTP_2.id)) {
            httpVersion = HttpVersion.HTTP_2;
        } else {
            throw new ProtocolNegotiationException("Unsupported application protocol: " + appProtocol);
        }
    } else {
        httpVersion = HttpVersion.HTTP_1_1;
    }
    startProtocol(httpVersion);
}
Also used : TlsDetails(org.apache.hc.core5.reactor.ssl.TlsDetails) HttpVersion(org.apache.hc.core5.http.HttpVersion)

Aggregations

TlsDetails (org.apache.hc.core5.reactor.ssl.TlsDetails)3 IOException (java.io.IOException)1 HttpVersion (org.apache.hc.core5.http.HttpVersion)1 ServerHttp1IOEventHandler (org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler)1