Search in sources :

Example 91 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project reactor-netty by reactor.

the class ProxyProvider method addProxyHandler.

public void addProxyHandler(Channel channel) {
    Objects.requireNonNull(channel, "channel");
    ChannelPipeline pipeline = channel.pipeline();
    pipeline.addFirst(NettyPipeline.ProxyHandler, newProxyHandler());
    if (pipeline.get(NettyPipeline.LoggingHandler) != null) {
        pipeline.addBefore(NettyPipeline.ProxyHandler, NettyPipeline.ProxyLoggingHandler, LOGGING_HANDLER);
    }
}
Also used : ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 92 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project reactor-netty by reactor.

the class SslProvider method addSslHandler.

public void addSslHandler(Channel channel, @Nullable SocketAddress remoteAddress, boolean sslDebug, boolean enableTracing) {
    Objects.requireNonNull(channel, "channel");
    if (sniProvider != null) {
        sniProvider.addSniHandler(channel, sslDebug, enableTracing);
        return;
    }
    SslHandler sslHandler;
    if (remoteAddress instanceof InetSocketAddress) {
        InetSocketAddress sniInfo = (InetSocketAddress) remoteAddress;
        sslHandler = getSslContext().newHandler(channel.alloc(), sniInfo.getHostString(), sniInfo.getPort());
        if (log.isDebugEnabled()) {
            log.debug(format(channel, "SSL enabled using engine {} and SNI {}"), sslHandler.engine(), sniInfo);
        }
    } else {
        sslHandler = getSslContext().newHandler(channel.alloc());
        if (log.isDebugEnabled()) {
            log.debug(format(channel, "SSL enabled using engine {}"), sslHandler.engine());
        }
    }
    configure(sslHandler);
    ChannelPipeline pipeline = channel.pipeline();
    if (pipeline.get(NettyPipeline.ProxyHandler) != null) {
        pipeline.addAfter(NettyPipeline.ProxyHandler, NettyPipeline.SslHandler, sslHandler);
    } else if (pipeline.get(NettyPipeline.NonSslRedirectDetector) != null) {
        pipeline.addAfter(NettyPipeline.NonSslRedirectDetector, NettyPipeline.SslHandler, sslHandler);
    } else {
        pipeline.addFirst(NettyPipeline.SslHandler, sslHandler);
    }
    addSslReadHandler(pipeline, sslDebug, remoteAddress == null, enableTracing);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SslHandler(io.netty.handler.ssl.SslHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 93 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project reactor-netty by reactor.

the class HttpServerConfig method addStreamHandlers.

static void addStreamHandlers(Channel ch, boolean accessLogEnabled, @Nullable Function<AccessLogArgProvider, AccessLog> accessLog, @Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compressPredicate, ServerCookieDecoder decoder, ServerCookieEncoder encoder, HttpServerFormDecoderProvider formDecoderProvider, @Nullable BiFunction<ConnectionInfo, HttpRequest, ConnectionInfo> forwardedHeaderHandler, ConnectionObserver listener, @Nullable BiFunction<? super Mono<Void>, ? super Connection, ? extends Mono<Void>> mapHandle, int minCompressionSize, ChannelOperations.OnSetup opsFactory) {
    ChannelPipeline pipeline = ch.pipeline();
    if (accessLogEnabled) {
        pipeline.addLast(NettyPipeline.AccessLogHandler, AccessLogHandlerFactory.H2.create(accessLog));
    }
    pipeline.addLast(NettyPipeline.H2ToHttp11Codec, new Http2StreamFrameToHttpObjectCodec(true)).addLast(NettyPipeline.HttpTrafficHandler, new Http2StreamBridgeServerHandler(compressPredicate, decoder, encoder, formDecoderProvider, forwardedHeaderHandler, listener, mapHandle));
    boolean alwaysCompress = compressPredicate == null && minCompressionSize == 0;
    if (alwaysCompress) {
        pipeline.addLast(NettyPipeline.CompressionHandler, new SimpleCompressionHandler());
    }
    ChannelOperations.addReactiveBridge(ch, opsFactory, listener);
    if (log.isDebugEnabled()) {
        log.debug(format(ch, "Initialized HTTP/2 stream pipeline {}"), pipeline);
    }
}
Also used : Http2StreamFrameToHttpObjectCodec(io.netty.handler.codec.http2.Http2StreamFrameToHttpObjectCodec) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 94 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project reactor-netty by reactor.

the class NonSslRedirectDetector method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
    if (in.readableBytes() < SSL_RECORD_HEADER_LENGTH) {
        return;
    }
    ChannelPipeline pipeline = ctx.pipeline();
    if (SslHandler.isEncrypted(in)) {
        sslProvider.addSslHandler(ctx.channel(), remoteAddress, sslDebug);
    } else {
        pipeline.addBefore(NettyPipeline.ReactiveBridge, NettyPipeline.NonSslRedirectHandler, new NonSslRedirectHandler());
    }
    pipeline.remove(this);
}
Also used : ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 95 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project apollo by apollo-rsps.

the class ServiceChannelInitializer method initChannel.

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("handshakeDecoder", new HandshakeDecoder());
    pipeline.addLast("timeout", new IdleStateHandler(NetworkConstants.IDLE_TIME, 0, 0));
    pipeline.addLast("handler", handler);
}
Also used : IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) HandshakeDecoder(org.apollo.net.codec.handshake.HandshakeDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)370 SocketChannel (io.netty.channel.socket.SocketChannel)107 Channel (io.netty.channel.Channel)90 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)90 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)80 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)78 Bootstrap (io.netty.bootstrap.Bootstrap)77 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)69 ChannelFuture (io.netty.channel.ChannelFuture)68 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)62 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)62 EventLoopGroup (io.netty.channel.EventLoopGroup)54 SslHandler (io.netty.handler.ssl.SslHandler)52 InetSocketAddress (java.net.InetSocketAddress)49 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)43 LoggingHandler (io.netty.handler.logging.LoggingHandler)37 IOException (java.io.IOException)37 StringDecoder (io.netty.handler.codec.string.StringDecoder)36 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)36 StringEncoder (io.netty.handler.codec.string.StringEncoder)33