/** * Adds pipelines to channel. * * @param ch channel to be operated on */ protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipe = ch.pipeline(); if (ssl) { // HTTPs connection SSLEngine sslEng = getSsl(null); sslEng.setUseClientMode(true); pipe.addLast("SSL", new SslHandler(sslEng, false)); } pipe.addFirst("Timer", new ReadTimeoutHandler(30)); pipe.addLast("Codec", new HttpClientCodec()); pipe.addLast("Inflater", new HttpContentDecompressor()); pipe.addLast("Handler", new HTTPMessageHandler(builder)); }
@Override public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. ChannelPipeline p = ch.pipeline(); p.addLast("log", new LoggingHandler(LogLevel.INFO)); // Enable HTTPS if necessary. /* if (ssl) { SSLEngine engine = SecureChatSslContextFactory.getClientContext().createSSLEngine(); engine.setUseClientMode(true); p.addLast("ssl", new SslHandler(engine)); }*/ p.addLast("codec", new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. p.addLast("inflater", new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpChunks. //p.addLast("aggregator", new HttpObjectAggregator(1048576)); p.addLast("handler", new HttpSnoopClientHandler()); }
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc())); } pipeline.addLast("codec", new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. pipeline.addLast("inflater", new HttpContentDecompressor()); // to be used since huge file transfer pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); pipeline.addLast("handler", new HttpUploadClientHandler()); }
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); // Enable HTTPS if necessary. if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. p.addLast(new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpContents. //p.addLast(new HttpObjectAggregator(1048576)); p.addLast(new HttpSnoopClientHandler()); }
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); // Enable HTTPS if necessary. // if (sslCtx != null) { // pipeline.addLast(sslCtx.newHandler(ch.alloc())); // } pipeline.addLast(new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. pipeline.addLast(new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpContents. //pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new HttpObjectAggregator(65536 * 3)); // pipeline.addLast(new HttpClientHandler(null, mHttpClientListener)); }
@Override public void configNewChannel(NioSocketChannel channel) { super.configNewChannel(channel); ChannelPipeline pipeline = channel.pipeline(); // 添加 SSL 数据支持 if (requestConfig.https()) { SslContext sslContent = NettyCenter.singleInstance().getSimpleClientSslContext(); SSLEngine engine = sslContent.newEngine(channel.alloc()); pipeline.addLast("ssl", new SslHandler(engine)); } // 客户端接收到的是httpResponse响应,所以要使用HttpResponseDecoder进行解码 pipeline.addLast("decoder", new HttpResponseDecoder()); // 客户端发送的是httprequest,所以要使用HttpRequestEncoder进行编码 pipeline.addLast("encoder", new HttpRequestEncoder()); // 接收的请求累计器 pipeline.addLast("aggegator", new HttpObjectAggregator(0x30000)); // mime 类型写出 pipeline.addLast("streamew", new ChunkedWriteHandler()); // 添加解压器 pipeline.addLast("decompressor", new HttpContentDecompressor()); // add new handler pipeline.addLast("handler", new NettyHttpRequestChannelHandler()); }
@Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); //inbound handler pipeline.addLast(new HttpRequestDecoder()); pipeline.addLast(new HttpContentDecompressor()); //outbound handler pipeline.addLast(new HttpResponseEncoder()); pipeline.addLast(new HttpContentCompressor()); //pipeline.addLast(new ChunkedWriteHandler()); pipeline.addLast(new HttpObjectAggregator(this.sc.getSize())); pipeline.addLast(this.galeHttpHandler); }
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); // Enable HTTPS if necessary. if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. p.addLast(new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpContents. //p.addLast(new HttpObjectAggregator(1048576)); p.addLast(handler); }
@Override public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. ChannelPipeline pipeline = ch.pipeline(); if (ssl) { SSLEngine engine = SecureChatSslContextFactory.getClientContext().createSSLEngine(); engine.setUseClientMode(true); pipeline.addLast("ssl", new SslHandler(engine)); } pipeline.addLast("codec", new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. pipeline.addLast("inflater", new HttpContentDecompressor()); // to be used since huge file transfer pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); pipeline.addLast("handler", new HttpUploadClientHandler()); }
@Override public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. ChannelPipeline p = ch.pipeline(); p.addLast("log", new LoggingHandler(LogLevel.INFO)); // Enable HTTPS if necessary. if (ssl) { SSLEngine engine = SecureChatSslContextFactory.getClientContext().createSSLEngine(); engine.setUseClientMode(true); p.addLast("ssl", new SslHandler(engine)); } p.addLast("codec", new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. p.addLast("inflater", new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpChunks. //p.addLast("aggregator", new HttpObjectAggregator(1048576)); p.addLast("handler", new HttpSnoopClientHandler()); }
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); // Enable HTTPS if necessary. if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new HttpClientCodec()); // Remove the following line if you don't want automatic content decompression. p.addLast(new HttpContentDecompressor()); // Uncomment the following line if you don't want to handle HttpContents. p.addLast(new HttpObjectAggregator(1048576)); p.addLast(nettyHttpClientHandler); }
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("http-request-decoder", new HttpRequestDecoder()); pipeline.addLast("deflater", new HttpContentDecompressor()); pipeline.addLast("http-object-aggregator", new HttpObjectAggregator(1048576)); pipeline.addLast("http-response-encoder", new HttpResponseEncoder()); pipeline.addLast("inflater", new HttpContentCompressor()); // Alters the pipeline depending on either REST or WebSockets requests pipeline.addLast("api-protocol-switcher", apiProtocolSwitcher); pipeline.addLast("debugger", debugger); // Logging handlers for API requests pipeline.addLast("api-request-logger", apiRequestLogger); // pipeline.addLast(rxJavaGroup, "rxjava-handler", rxjavaHandler); // JAX-RS handlers pipeline.addLast(jaxRsGroup, "jax-rs-handler", jaxRsHandlers); }
private void switchToHttp(ChannelHandlerContext ctx, ByteBuf msg) { ChannelPipeline pipeline = ctx.pipeline(); addLastIfNotPresent(pipeline, new HttpServerCodec(8192, 8192, 8192)); addLastIfNotPresent(pipeline, new HttpContentDecompressor()); addLastIfNotPresent(pipeline, httpContentLengthRemover); addLastIfNotPresent(pipeline, new HttpObjectAggregator(Integer.MAX_VALUE)); if (mockServerLogger.isEnabled(TRACE)) { addLastIfNotPresent(pipeline, loggingHandler); } configurePipeline(ctx, pipeline); pipeline.remove(this); ctx.channel().attr(LOCAL_HOST_HEADERS).set(getLocalAddresses(ctx)); // fire message back through pipeline ctx.fireChannelRead(msg); }
@Override public void prepare(final Benchmark benchmark) { this.concurrencyLevel = benchmark.concurrencyLevel; this.targetBacklog = benchmark.targetBacklog; ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); if (benchmark.tls) { SslClient sslClient = SslClient.localhost(); SSLEngine engine = sslClient.sslContext.createSSLEngine(); engine.setUseClientMode(true); pipeline.addLast("ssl", new SslHandler(engine)); } pipeline.addLast("codec", new HttpClientCodec()); pipeline.addLast("inflater", new HttpContentDecompressor()); pipeline.addLast("handler", new HttpChannel(channel)); } }; bootstrap = new Bootstrap(); bootstrap.group(new NioEventLoopGroup(concurrencyLevel)) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .channel(NioSocketChannel.class) .handler(channelInitializer); }
@Override protected void initChannel(Channel ch) throws Exception { ch.pipeline().addLast("openChannels", transport.serverOpenChannels); final HttpRequestDecoder decoder = new HttpRequestDecoder( Math.toIntExact(transport.maxInitialLineLength.getBytes()), Math.toIntExact(transport.maxHeaderSize.getBytes()), Math.toIntExact(transport.maxChunkSize.getBytes())); decoder.setCumulator(ByteToMessageDecoder.COMPOSITE_CUMULATOR); ch.pipeline().addLast("decoder", decoder); ch.pipeline().addLast("decoder_compress", new HttpContentDecompressor()); ch.pipeline().addLast("encoder", new HttpResponseEncoder()); final HttpObjectAggregator aggregator = new HttpObjectAggregator(Math.toIntExact(transport.maxContentLength.getBytes())); if (transport.maxCompositeBufferComponents != -1) { aggregator.setMaxCumulationBufferComponents(transport.maxCompositeBufferComponents); } ch.pipeline().addLast("aggregator", aggregator); if (transport.compression) { ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(transport.compressionLevel)); } if (SETTING_CORS_ENABLED.get(transport.settings())) { ch.pipeline().addLast("cors", new Netty4CorsHandler(transport.getCorsConfig())); } if (transport.pipelining) { ch.pipeline().addLast("pipelining", new HttpPipeliningHandler(transport.pipeliningMaxEvents)); } ch.pipeline().addLast("handler", requestHandler); }
protected ChannelHandler setupHttpChannel(Configuration config, SslContext sslCtx) { return new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("ssl", new NonSslRedirectHandler(config, sslCtx)); ch.pipeline().addLast("encoder", new HttpResponseEncoder()); ch.pipeline().addLast("decoder", new HttpRequestDecoder()); ch.pipeline().addLast("compressor", new HttpContentCompressor()); ch.pipeline().addLast("decompressor", new HttpContentDecompressor()); ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192)); ch.pipeline().addLast("chunker", new ChunkedWriteHandler()); final Configuration.Cors corsCfg = config.getHttp().getCors(); final CorsConfig.Builder ccb; if (corsCfg.isAllowAnyOrigin()) { ccb = new CorsConfig.Builder(); } else { ccb = new CorsConfig.Builder(corsCfg.getAllowedOrigins().stream().toArray(String[]::new)); } if (corsCfg.isAllowNullOrigin()) { ccb.allowNullOrigin(); } if (corsCfg.isAllowCredentials()) { ccb.allowCredentials(); } corsCfg.getAllowedMethods().stream().map(HttpMethod::valueOf).forEach(ccb::allowedRequestMethods); corsCfg.getAllowedHeaders().forEach(ccb::allowedRequestHeaders); CorsConfig cors = ccb.build(); LOG.trace("Cors configuration: {}", cors); ch.pipeline().addLast("cors", new CorsHandler(cors)); ch.pipeline().addLast("queryDecoder", new qonduit.netty.http.HttpRequestDecoder(config)); ch.pipeline().addLast("strict", new StrictTransportHandler(config)); ch.pipeline().addLast("login", new X509LoginRequestHandler(config)); ch.pipeline().addLast("doLogin", new BasicAuthLoginRequestHandler(config)); ch.pipeline().addLast("error", new HttpExceptionHandler()); } }; }
@Override protected ChannelHandler setupHttpChannel(Configuration config, SslContext sslCtx) { return new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("ssl", new NonSslRedirectHandler(config, sslCtx)); ch.pipeline().addLast("decompressor", new HttpContentDecompressor()); ch.pipeline().addLast("decoder", new HttpRequestDecoder()); ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192)); ch.pipeline().addLast("queryDecoder", new qonduit.netty.http.HttpRequestDecoder(config)); ch.pipeline().addLast("capture", httpRequests); } }; }
@Override public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) throws Exception { if (match(httpResponse, pipeline)) { isMatch = true; //解压gzip响应 if ("gzip".equalsIgnoreCase(httpResponse.headers().get(HttpHeaderNames.CONTENT_ENCODING))) { isGzip = true; pipeline.reset3(); proxyChannel.pipeline().addAfter("httpCodec", "decompress", new HttpContentDecompressor()); proxyChannel.pipeline().fireChannelRead(httpResponse); } else { if (isGzip) { httpResponse.headers().set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.GZIP); } contentBuf = PooledByteBufAllocator.DEFAULT.buffer(); /*contentBuf.writeBytes(hookResponse().getBytes()); for (HttpProxyIntercept intercept : pipeline) { if (intercept != this && intercept instanceof ResponseTextIntercept) { ResponseTextIntercept textIntercept = (ResponseTextIntercept) intercept; if (textIntercept.match(httpResponse, pipeline)) { contentBuf.writeBytes(textIntercept.hookResponse().getBytes()); } } }*/ } //直接调用默认拦截器,跳过下载拦截器 pipeline.getDefault() .afterResponse(clientChannel, proxyChannel, httpResponse, pipeline); } else { isMatch = false; pipeline.afterResponse(clientChannel, proxyChannel, httpResponse); } }
@Override public void prepare(final Benchmark benchmark) { this.concurrencyLevel = benchmark.concurrencyLevel; this.targetBacklog = benchmark.targetBacklog; ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); if (benchmark.tls) { SSLContext sslContext = SslContextBuilder.localhost(); SSLEngine engine = sslContext.createSSLEngine(); engine.setUseClientMode(true); pipeline.addLast("ssl", new SslHandler(engine)); } pipeline.addLast("codec", new HttpClientCodec()); pipeline.addLast("inflater", new HttpContentDecompressor()); pipeline.addLast("handler", new HttpChannel(channel)); } }; bootstrap = new Bootstrap(); bootstrap.group(new NioEventLoopGroup(concurrencyLevel)) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .channel(NioSocketChannel.class) .handler(channelInitializer); }
@Override protected ChannelHandler setupHttpChannel(Configuration config, SslContext sslCtx) { return new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("ssl", new NonSslRedirectHandler(config, sslCtx)); ch.pipeline().addLast("decompressor", new HttpContentDecompressor()); ch.pipeline().addLast("decoder", new HttpRequestDecoder()); ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192)); ch.pipeline().addLast("queryDecoder", new timely.netty.http.HttpRequestDecoder(config)); ch.pipeline().addLast("capture", httpRequests); } }; }
private HttpContentDecompressor newHttpContentDecompressor() { if (config.isKeepEncodingHeader()) return new HttpContentDecompressor() { @Override protected String getTargetContentEncoding(String contentEncoding) throws Exception { return contentEncoding; } }; else return new HttpContentDecompressor(); }
@Override protected void initChannel(final SocketChannel sc) throws Exception { ChannelPipeline p = sc.pipeline(); p.addLast(new HttpContentCompressor()); p.addLast(new HttpClientCodec()); p.addLast(new HttpContentDecompressor()); p.addLast(new HttpObjectAggregator(1048576)); }
/** * Modifies the pipeline to handle HTTP requests * @param ctx The calling channel handler context * @param maxRequestSize The maximum request size in bytes */ private void switchToHttp(final ChannelHandlerContext ctx, final int maxRequestSize) { ChannelPipeline p = ctx.pipeline(); p.addLast("httpHandler", new HttpServerCodec()); // TODO: config ? p.addLast("decompressor", new HttpContentDecompressor()); p.addLast("aggregator", new HttpObjectAggregator(maxRequestSize)); p.addLast("jsonDecoder", new JsonObjectDecoder(maxRequestSize, false)); p.addLast("handler", jsonRpcHandler); p.remove(this); }
@Override public void initChannel(final SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); //p.addLast("timeout", new IdleStateHandler(0, 0, 60)); // TODO: configurable p.addLast("httpcodec", new HttpClientCodec()); p.addLast("inflater", new HttpContentDecompressor()); //p.addLast("aggregator", new HttpObjectAggregator(1048576)); p.addLast("qdecoder", queryResultDecoder); // p.addLast("logging", loggingHandler); }
/** * {@inheritDoc} * @see io.netty.channel.pool.ChannelPoolHandler#channelCreated(io.netty.channel.Channel) */ @Override public void channelCreated(final Channel ch) throws Exception { log.debug("Channel Created: {}", ch); channelGroup.add(ch); final ChannelPipeline p = ch.pipeline(); //p.addLast("timeout", new IdleStateHandler(0, 0, 60)); // TODO: configurable p.addLast("httpcodec", new HttpClientCodec()); p.addLast("inflater", new HttpContentDecompressor()); // p.addLast("deflater", new HttpContentCompressor()); p.addLast("aggregator", new HttpObjectAggregator(20485760)); // p.addLast("logging", loggingHandler); p.addLast("qdecoder", queryResultDecoder); }
@Override public void accept(ChannelPipeline pipeline, ContextHandler<Channel> c) { pipeline.addLast(NettyPipeline.HttpCodec, new HttpClientCodec()); if (options.acceptGzip()) { pipeline.addAfter(NettyPipeline.HttpCodec, NettyPipeline.HttpDecompressor, new HttpContentDecompressor()); } }
@Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast("log", new LoggingHandler(LogLevel.TRACE)); p.addLast("codec", new HttpClientCodec()); p.addLast("inflater", new HttpContentDecompressor()); // p.addLast("aggregator", new HttpObjectAggregator(10 * 1024 * 1024)); p.addLast("handler", handler); }
@Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); List<ChannelHandler> decoders = new ArrayList<ChannelHandler>(); decoders.add(new HttpContentDecompressor()); registry.bind("myDecoders", decoders); return registry; }
@Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new HttpClientCodec()); p.addLast(new HttpContentDecompressor()); p.addLast(handler); }