Java Code Examples for io.netty.handler.ssl.ApplicationProtocolNames#HTTP_1_1

The following examples show how to use io.netty.handler.ssl.ApplicationProtocolNames#HTTP_1_1 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpServerConfig.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
H2OrHttp11Codec(
		@Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compressPredicate,
		ServerCookieDecoder cookieDecoder,
		ServerCookieEncoder cookieEncoder,
		HttpRequestDecoderSpec decoder,
		boolean forwarded,
		Http2Settings http2Settings,
		ConnectionObserver listener,
		@Nullable Supplier<? extends ChannelMetricsRecorder> metricsRecorder,
		int minCompressionSize,
		ChannelOperations.OnSetup opsFactory,
		@Nullable Function<String, String> uriTagValue) {
	super(ApplicationProtocolNames.HTTP_1_1);
	this.compressPredicate = compressPredicate;
	this.cookieDecoder = cookieDecoder;
	this.cookieEncoder = cookieEncoder;
	this.decoder = decoder;
	this.forwarded = forwarded;
	this.http2Settings = http2Settings;
	this.listener = listener;
	this.metricsRecorder = metricsRecorder;
	this.minCompressionSize = minCompressionSize;
	this.opsFactory = opsFactory;
	this.uriTagValue = uriTagValue;
}
 
Example 2
Source File: Http2ConnectionProvider.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
boolean notHttp2() {
	Channel channel = pooledRef.poolable().channel();
	SslHandler handler = channel.pipeline().get(SslHandler.class);
	if (handler != null) {
		String protocol = handler.applicationProtocol() != null ? handler.applicationProtocol() : ApplicationProtocolNames.HTTP_1_1;
		if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
			// No information for the negotiated application-level protocol
			// or it is HTTP/1.1, continue as an HTTP/1.1 request
			// and remove the connection from this pool.
			ChannelOperations<?, ?> ops = ChannelOperations.get(channel);
			if (ops != null) {
				sink.success(ops);
				invalidate(this, channel);
				return true;
			}
		}
		else if (!ApplicationProtocolNames.HTTP_2.equals(handler.applicationProtocol())) {
			channel.attr(OWNER).set(null);
			invalidate(this, channel);
			sink.error(new IOException("Unknown protocol [" + protocol + "]."));
			return true;
		}
	}
	return false;
}
 
Example 3
Source File: HttpClientConfig.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) {
	SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
	if (sslHandler == null) {
		throw new IllegalStateException("Cannot determine negotiated application-level protocol.");
	}
	String protocol = sslHandler.applicationProtocol() != null ? sslHandler.applicationProtocol() : ApplicationProtocolNames.HTTP_1_1;
	if (log.isDebugEnabled()) {
		log.debug(format(ctx.channel(), "Negotiated application-level protocol [" + protocol + "]"));
	}
	if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
		configureHttp2Pipeline(ctx.channel().pipeline(), decoder, http2Settings, observer);
	}
	else if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
		configureHttp11Pipeline(ctx.channel().pipeline(), acceptGzip, decoder, metricsRecorder, uriTagValue);
	}
	else {
		throw new IllegalStateException("unknown protocol: " + protocol);
	}

	ctx.fireChannelActive();

	ctx.channel().pipeline().remove(this);
}
 
Example 4
Source File: TlsUtil.java    From nitmproxy with MIT License 6 votes vote down vote up
private static ApplicationProtocolConfig applicationProtocolConfig(NitmProxyConfig config, boolean http2) {
    if (http2) {
        return new ApplicationProtocolConfig(
                Protocol.ALPN,
                SelectorFailureBehavior.NO_ADVERTISE,
                SelectedListenerFailureBehavior.ACCEPT,
                ApplicationProtocolNames.HTTP_2,
                ApplicationProtocolNames.HTTP_1_1);
    } else {
        return new ApplicationProtocolConfig(
                Protocol.ALPN,
                SelectorFailureBehavior.NO_ADVERTISE,
                SelectedListenerFailureBehavior.ACCEPT,
                ApplicationProtocolNames.HTTP_1_1);
    }
}
 
Example 5
Source File: Http2Configuration.java    From zuul with Apache License 2.0 5 votes vote down vote up
public static SslContext configureSSL(SslContextFactory sslContextFactory, String metricId) {
    SslContextBuilder builder = sslContextFactory.createBuilderForServer();

    String[] supportedProtocol;
    if (HTTP2_DISABLED.get()) {
        supportedProtocol = new String[]{ApplicationProtocolNames.HTTP_1_1};
    }
    else {
        supportedProtocol = new String[]{ApplicationProtocolNames.HTTP_2,
                ApplicationProtocolNames.HTTP_1_1};
    }

    ApplicationProtocolConfig apn = new ApplicationProtocolConfig(
            ApplicationProtocolConfig.Protocol.ALPN,
            // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
            ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE,
            // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
            ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT,
            supportedProtocol);

    final SslContext sslContext;
    try {
        sslContext = builder
                .applicationProtocolConfig(apn)
                .build();
    }
    catch (SSLException e) {
        throw new RuntimeException("Error configuring SslContext with ALPN!", e);
    }

    // Enable TLS Session Tickets support.
    sslContextFactory.enableSessionTickets(sslContext);

    // Setup metrics tracking the OpenSSL stats.
    sslContextFactory.configureOpenSslStatsMetrics(sslContext, metricId);

    return sslContext;
}
 
Example 6
Source File: Http2OrHttpHandler.java    From zuul with Apache License 2.0 5 votes vote down vote up
public Http2OrHttpHandler(ChannelHandler http2StreamHandler, ChannelConfig channelConfig,
                          Consumer<ChannelPipeline> addHttpHandlerFn) {
    super(ApplicationProtocolNames.HTTP_1_1);
    this.http2StreamHandler = http2StreamHandler;
    this.maxConcurrentStreams = channelConfig.get(CommonChannelConfigKeys.maxConcurrentStreams);
    this.initialWindowSize = channelConfig.get(CommonChannelConfigKeys.initialWindowSize);
    this.maxHeaderTableSize = channelConfig.get(CommonChannelConfigKeys.maxHttp2HeaderTableSize);
    this.maxHeaderListSize = channelConfig.get(CommonChannelConfigKeys.maxHttp2HeaderListSize);
    this.addHttpHandlerFn = addHttpHandlerFn;
}
 
Example 7
Source File: Http2OrHttpHandler.java    From xrpc with Apache License 2.0 5 votes vote down vote up
protected Http2OrHttpHandler(
    UrlRouter router, ServerContext xctx, CorsConfig corsConfig, int maxPayloadBytes) {
  super(ApplicationProtocolNames.HTTP_1_1);
  this.router = router;
  this.xctx = xctx;
  this.corsConfig = corsConfig;
  this.maxPayloadBytes = maxPayloadBytes;
}
 
Example 8
Source File: HttpServletProtocolSpringAdapter.java    From spring-boot-protocol with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the SSL security configuration for HTTPS
 * @param keyManagerFactory keyManagerFactory
 * @param ssl ssl
 * @param sslStoreProvider sslStoreProvider
 * @return The SSL context builder
 * @throws Exception Exception
 */
protected SslContextBuilder getSslContext(KeyManagerFactory keyManagerFactory, Ssl ssl, SslStoreProvider sslStoreProvider) throws Exception {
    SslContextBuilder builder = SslContextBuilder.forServer(keyManagerFactory);
    builder.trustManager(getTrustManagerFactory(ssl, sslStoreProvider));
    if (ssl.getEnabledProtocols() != null) {
        builder.protocols(ssl.getEnabledProtocols());
    }
    if (ssl.getCiphers() != null) {
        builder.ciphers(Arrays.asList(ssl.getCiphers()));
    }
    if (ssl.getClientAuth() == Ssl.ClientAuth.NEED) {
        builder.clientAuth(ClientAuth.REQUIRE);
    }
    else if (ssl.getClientAuth() == Ssl.ClientAuth.WANT) {
        builder.clientAuth(ClientAuth.OPTIONAL);
    }

    ApplicationProtocolConfig protocolConfig = new ApplicationProtocolConfig(
            ApplicationProtocolConfig.Protocol.ALPN,
            // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
            ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE,
            // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
            ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT,
            ApplicationProtocolNames.HTTP_2,
            ApplicationProtocolNames.HTTP_1_1);
    builder.applicationProtocolConfig(protocolConfig);

    return builder;
}
 
Example 9
Source File: Http2Server.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static SslContext configureTLS() throws CertificateException, SSLException {
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    ApplicationProtocolConfig apn = new ApplicationProtocolConfig(
            Protocol.ALPN,
            // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
            SelectorFailureBehavior.NO_ADVERTISE,
            // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
            SelectedListenerFailureBehavior.ACCEPT,
            ApplicationProtocolNames.HTTP_2,
            ApplicationProtocolNames.HTTP_1_1);

    return SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey(), null)
                            .ciphers(CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
                            .applicationProtocolConfig(apn).build();
}
 
Example 10
Source File: Http2OrHttpHandler.java    From product-microgateway with Apache License 2.0 4 votes vote down vote up
protected Http2OrHttpHandler() {
    super(ApplicationProtocolNames.HTTP_1_1);
}
 
Example 11
Source File: SpdyOrHttpHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
protected SpdyOrHttpHandler() {
    super(ApplicationProtocolNames.HTTP_1_1);
}
 
Example 12
Source File: TlsHandler.java    From nitmproxy with MIT License 4 votes vote down vote up
private AlpnHandler(ChannelHandlerContext tlsCtx) {
    super(ApplicationProtocolNames.HTTP_1_1);
    this.tlsCtx = tlsCtx;
}
 
Example 13
Source File: Http2OrHttpHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
protected Http2OrHttpHandler() {
    super(ApplicationProtocolNames.HTTP_1_1);
}
 
Example 14
Source File: Http2OrHttpHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
protected Http2OrHttpHandler() {
    super(ApplicationProtocolNames.HTTP_1_1);
}
 
Example 15
Source File: HttpServerPipelineConfigurator.java    From armeria with Apache License 2.0 4 votes vote down vote up
Http2OrHttpHandler(@Nullable ProxiedAddresses proxiedAddresses) {
    super(ApplicationProtocolNames.HTTP_1_1);
    this.proxiedAddresses = proxiedAddresses;
}
 
Example 16
Source File: HttpClientNegotiationHandler.java    From xio with Apache License 2.0 4 votes vote down vote up
public HttpClientNegotiationHandler(Supplier<ChannelHandler> http2Handler) {
  super(ApplicationProtocolNames.HTTP_1_1);
  this.http2Handler = http2Handler;
}
 
Example 17
Source File: HttpNegotiationHandler.java    From xio with Apache License 2.0 4 votes vote down vote up
public HttpNegotiationHandler(Supplier<ChannelHandler> http2Handler) {
  super(ApplicationProtocolNames.HTTP_1_1);
  this.http2Handler = http2Handler;
}
 
Example 18
Source File: Http2OrHttpHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
protected Http2OrHttpHandler() {
    super(ApplicationProtocolNames.HTTP_1_1);
}
 
Example 19
Source File: Http2OrHttpHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
protected Http2OrHttpHandler() {
    super(ApplicationProtocolNames.HTTP_1_1);
}