@Override public ChannelPipeline replace(ChannelHandler oldHandler, String newName, ChannelHandler newHandler) { delegate.replace(oldHandler, newName, newHandler); return this; }
@Override public ChannelHandler replace(String oldName, String newName, ChannelHandler newHandler) { return delegate.replace(oldName, newName, newHandler); }
@Override public <T extends ChannelHandler> T replace(Class<T> oldHandlerType, String newName, ChannelHandler newHandler) { return delegate.replace(oldHandlerType, newName, newHandler); }
protected void http1Codec(ChannelPipeline pipeline) { pipeline.replace("codec_placeholder", HTTP_CODEC_HANDLER_NAME, createHttpServerCodec()); } }
private void handleNonSsl(ChannelHandlerContext context) { ChannelHandler handler = newNonSslHandler(context); if (handler != null) { context.pipeline().replace(this, newNonSslHandlerName(), handler); } else { context.pipeline().remove(this); } }
@Override public void handlerAdded(ChannelHandlerContext ctx) { ctx.pipeline().replace(this, null, new PortUnificationHandler(server, httpStateHandler, proxyConfiguration)); } }
@Override public ChannelHandler replace(String oldName, String newName, ChannelHandler newHandler) { return pipeline.replace(oldName, newName, newHandler); }
/** * Replaces this entry of handler in the netty pipeline with the provided SslHandler and maintains the handler name * * @param sslHandler configured netty handler that enables TLS */ private void replaceSelfWith( SslHandler sslHandler ) { String myName = pipeline.toMap() .entrySet() .stream() .filter( entry -> this.equals( entry.getValue() ) ) .map( Map.Entry::getKey ) .findFirst() .orElseThrow( () -> new IllegalStateException( "This handler has no name" ) ); pipeline.replace( this, myName, sslHandler ); pipeline.addAfter( myName, "handshakeCompletionSslDetailsHandler", new HandshakeCompletionSslDetailsHandler() ); }
private void handleNonSsl(ChannelHandlerContext context) { ChannelHandler handler = newNonSslHandler(context); if (handler != null) { context.pipeline().replace(this, newNonSslHandlerName(), handler); } else { context.pipeline().remove(this); } }
/** * The default implementation of this method will simply replace {@code this} {@link SniHandler} * instance with a {@link SslHandler}. Users may override this method to implement custom behavior. * * Please be aware that this method may get called after a client has already disconnected and * custom implementations must take it into consideration when overriding this method. * * It's also possible for the hostname argument to be {@code null}. */ protected void replaceHandler(ChannelHandlerContext ctx, String hostname, SslContext sslContext) throws Exception { SslHandler sslHandler = null; try { sslHandler = sslContext.newHandler(ctx.alloc()); ctx.pipeline().replace(this, SslHandler.class.getName(), sslHandler); sslHandler = null; } finally { // Since the SslHandler was not inserted into the pipeline the ownership of the SSLEngine was not // transferred to the SslHandler. // See https://github.com/netty/netty/issues/5678 if (sslHandler != null) { ReferenceCountUtil.safeRelease(sslHandler.engine()); } } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // TODO graceful validation ByteBuf bf = ((ByteBuf) msg).copy(); Http2Validator validator = new Http2Validator(); validator.channelRead(null, bf); if (validator.isHttp2()) { ctx.pipeline().replace(this, null, handler); } else { ctx.pipeline().addLast("http-decoder", new HttpRequestDecoder()); ctx.pipeline().addLast("http-aggregator", new HttpObjectAggregator(maxContentLength)); ctx.pipeline().addLast("http-encoder", new HttpResponseEncoder()); ctx.pipeline().addLast("http-chunked", new ChunkedWriteHandler()); ctx.pipeline().addLast("serverHandler", httpHandler); } ctx.fireChannelRead(msg); } }
private void handlePasswordAuthRequest(ChannelHandlerContext ctx, Socks5PasswordAuthRequest passwordAuthRequest) { String username = ConfigurationProperties.proxyAuthenticationUsername(); String password = ConfigurationProperties.proxyAuthenticationPassword(); // we need the null-check again here, in case the properties got unset between init and auth request if (!username.isEmpty() && !password.isEmpty() && username.equals(passwordAuthRequest.username()) && password.equals(passwordAuthRequest.password())) { ctx.pipeline().replace(Socks5PasswordAuthRequestDecoder.class, null, new Socks5CommandRequestDecoder()); ctx.write(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS)); } else { ctx.writeAndFlush(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.FAILURE)).addListener(ChannelFutureListener.CLOSE); } }
protected void http1Codec(ChannelPipeline pipeline) { pipeline.replace("codec_placeholder", HTTP_CODEC_HANDLER_NAME, createHttpServerCodec()); } }
private void handleSsl(ChannelHandlerContext context) { SslHandler sslHandler = null; try { sslHandler = newSslHandler(context, sslContext); context.pipeline().replace(this, newSslHandlerName(), sslHandler); sslHandler = null; } finally { // Since the SslHandler was not inserted into the pipeline the ownership of the SSLEngine was not // transferred to the SslHandler. if (sslHandler != null) { ReferenceCountUtil.safeRelease(sslHandler.engine()); } } }
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. // "Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)"); ChannelPipeline pipeline = ctx.pipeline(); ChannelHandlerContext thisCtx = pipeline.context(this); pipeline.addAfter(thisCtx.name(), null, new JerseyServerHandler(baseUri, container)); pipeline.replace(this, null, new ChunkedWriteHandler()); ctx.fireChannelRead(msg); } });
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { ctx.pipeline() .addBefore(ctx.name(), null, new Http2ServerUpgradeHandler.PriorKnowledgeHandler()) .addBefore(ctx.name(), "HttpServerCodec", httpServerCodec) .replace(this, "HttpServerUpgradeHandler", httpServerUpgradeHandler); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { ctx.pipeline() .addBefore(ctx.name(), null, new Http2ServerUpgradeHandler.PriorKnowledgeHandler()) .addBefore(ctx.name(), "HttpServerCodec", httpServerCodec) .replace(this, "HttpServerUpgradeHandler", httpServerUpgradeHandler); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { ctx.pipeline() .addBefore(ctx.name(), null, new PriorKnowledgeHandler()) .addBefore(ctx.name(), null, httpServerCodec) .replace(this, null, httpServerUpgradeHandler); }
private void configureHttp2(ChannelPipeline pipeline) { // setup the initial stream settings for the server to use. Http2Settings settings = new Http2Settings() .maxConcurrentStreams(maxConcurrentStreams) .initialWindowSize(initialWindowSize) .headerTableSize(maxHeaderTableSize) .maxHeaderListSize(maxHeaderListSize); Http2MultiplexCodec multiplexCodec = Http2MultiplexCodecBuilder .forServer(http2StreamHandler) .frameLogger(FRAME_LOGGER) .initialSettings(settings) .validateHeaders(true) .build(); pipeline.replace("codec_placeholder", HTTP_CODEC_HANDLER_NAME, multiplexCodec); // Need to pass the connection to our handler later, so store it on channel now. Http2Connection connection = multiplexCodec.connection(); pipeline.channel().attr(H2_CONN_KEY).set(connection); }
private void configureHttp2(ChannelPipeline pipeline) { // setup the initial stream settings for the server to use. Http2Settings settings = new Http2Settings() .maxConcurrentStreams(maxConcurrentStreams) .initialWindowSize(initialWindowSize) .headerTableSize(maxHeaderTableSize) .maxHeaderListSize(maxHeaderListSize); Http2MultiplexCodec multiplexCodec = Http2MultiplexCodecBuilder .forServer(http2StreamHandler) .frameLogger(FRAME_LOGGER) .initialSettings(settings) .validateHeaders(true) .build(); pipeline.replace("codec_placeholder", HTTP_CODEC_HANDLER_NAME, multiplexCodec); // Need to pass the connection to our handler later, so store it on channel now. Http2Connection connection = multiplexCodec.connection(); pipeline.channel().attr(H2_CONN_KEY).set(connection); }