io.netty.handler.codec.http.HttpContentDecompressor Java Examples

The following examples show how to use io.netty.handler.codec.http.HttpContentDecompressor. 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: HttpUploadClientInitializer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: HttpClientInitializer.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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));
	}
 
Example #3
Source File: TestServer.java    From timely with Apache License 2.0 6 votes vote down vote up
@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.getHttp(), 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.getSecurity(), config.getHttp()));
            ch.pipeline().addLast("capture", httpRequests);
        }
    };
}
 
Example #4
Source File: HttpUploadClientIntializer.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #5
Source File: HttpSnoopClientInitializer.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #6
Source File: NettyClientInit.java    From jus with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #7
Source File: HttpCacheClient.java    From bazel with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
private void releaseDownloadChannel(Channel ch) {
  if (ch.isOpen()) {
    // The channel might have been closed due to an error, in which case its pipeline
    // has already been cleared. Closed channels can't be reused.
    try {
      ch.pipeline().remove(IdleTimeoutHandler.class);
      ch.pipeline().remove(HttpClientCodec.class);
      ch.pipeline().remove(HttpContentDecompressor.class);
      ch.pipeline().remove(HttpDownloadHandler.class);
    } catch (NoSuchElementException e) {
      // If the channel is in the process of closing but not yet closed, some handlers could have
      // been removed and would cause NoSuchElement exceptions to be thrown. Because handlers are
      // removed in reverse-order, if we get a NoSuchElement exception, the following handlers
      // should have been removed.
    }
  }
  channelPool.release(ch);
}
 
Example #8
Source File: HttpSnoopClientInitializer.java    From tools-journey with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #9
Source File: HttpUploadClientInitializer.java    From tools-journey with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #10
Source File: HttpClientInitializer.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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));
	}
 
Example #11
Source File: NettyDockerCmdExecFactory.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Override
public EventLoopGroup init(Bootstrap bootstrap, final DockerClientConfig dockerClientConfig) {
    EventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(0, new DefaultThreadFactory(threadPrefix));

    InetAddress addr = InetAddress.getLoopbackAddress();

    final SocketAddress proxyAddress = new InetSocketAddress(addr, 8008);

    Security.addProvider(new BouncyCastleProvider());

    ChannelFactory<NioSocketChannel> factory = () -> configure(new NioSocketChannel());

    bootstrap.group(nioEventLoopGroup).channelFactory(factory)
            .handler(new ChannelInitializer<SocketChannel>() {
                @Override
                protected void initChannel(final SocketChannel channel) throws Exception {
                    // channel.pipeline().addLast(new
                    // HttpProxyHandler(proxyAddress));
                    channel.pipeline().addLast(new HttpClientCodec());
                    channel.pipeline().addLast(new HttpContentDecompressor());
                }
            });

    return nioEventLoopGroup;
}
 
Example #12
Source File: HttpClient.java    From multi-model-server with Apache License 2.0 6 votes vote down vote up
private Bootstrap bootstrap(ClientHandler handler) {
    Bootstrap b = new Bootstrap();
    b.group(new NioEventLoopGroup(1))
            .channel(NioSocketChannel.class)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10 * 1000)
            .handler(
                    new ChannelInitializer<Channel>() {
                        @Override
                        public void initChannel(Channel ch) {
                            ChannelPipeline p = ch.pipeline();
                            p.addLast(new ReadTimeoutHandler(10 * 60 * 1000));
                            p.addLast(new HttpClientCodec());
                            p.addLast(new HttpContentDecompressor());
                            p.addLast(new ChunkedWriteHandler());
                            p.addLast(new HttpObjectAggregator(6553600));
                            p.addLast(handler);
                        }
                    });
    return b;
}
 
Example #13
Source File: HttpServerLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Before
public void setup() throws Exception {
    Bootstrap b = new Bootstrap();
    b.group(group)
        .channel(NioSocketChannel.class)
        .handler(new ChannelInitializer<SocketChannel>() {

            @Override
            protected void initChannel(SocketChannel ch) throws Exception {
                ChannelPipeline p = ch.pipeline();
                p.addLast(new HttpClientCodec());
                p.addLast(new HttpContentDecompressor());
                p.addLast(new SimpleChannelInboundHandler<HttpObject>() {
                    @Override
                    protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
                        response = prepareResponse(ctx, msg, response);
                    }
                });
            }
        });

    channel = b.connect(HOST, PORT)
        .sync()
        .channel();
}
 
Example #14
Source File: BackPoolHandler.java    From api-gateway-core with Apache License 2.0 6 votes vote down vote up
@Override
    public void channelCreated(Channel ch) throws Exception {
        logger.debug("channelCreated. Channel ID: {}", ch.id());
        NioSocketChannel channel = (NioSocketChannel) ch;
        channel.config().setKeepAlive(true);
        channel.config().setTcpNoDelay(true);
        ChannelPipeline pipeline = channel.pipeline();
        if (sslCtx != null) {
            pipeline.addLast(sslCtx.newHandler(ch.alloc()));
        }
        pipeline.addLast(new HttpClientCodec());
        pipeline.addLast(new HttpContentDecompressor());
        pipeline.addLast(new HttpObjectAggregator(1024 * 1024 * 64));
        pipeline.addLast(new ChunkedWriteHandler());
//        pipeline.addLast(new ReadTimeoutHandler(requestHolder.route.getTimeoutInMilliseconds(), TimeUnit.MILLISECONDS));
        pipeline.addLast(new BackHandler());
    }
 
Example #15
Source File: ResponseTextIntercept.java    From proxyee-down with Apache License 2.0 6 votes vote down vote up
@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();
    }
    //直接调用默认拦截器,跳过下载拦截器
    pipeline.getDefault()
        .afterResponse(clientChannel, proxyChannel, httpResponse, pipeline);
  } else {
    isMatch = false;
    pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
  }
}
 
Example #16
Source File: HttpSnoopClientInitializer.java    From julongchain with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();

    // 启用 HTTPS .
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }

    p.addLast(new HttpClientCodec());

    // 如果不想自动处理内容压缩请移除下面这一行.
    p.addLast(new HttpContentDecompressor());

    // 如果不想处理HttpContents就放开下面这行注释.
    //p.addLast(new HttpObjectAggregator(1048576));

    p.addLast(new HttpSnoopClientHandler());
}
 
Example #17
Source File: HttpSnoopClientInitializer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #18
Source File: Netty4HttpServerTransport.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void initChannel(Channel ch) throws Exception {
    ch.pipeline().addLast("openChannels", transport.serverOpenChannels);
    ch.pipeline().addLast("read_timeout", new ReadTimeoutHandler(transport.readTimeoutMillis, TimeUnit.MILLISECONDS));
    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()));
    aggregator.setMaxCumulationBufferComponents(transport.maxCompositeBufferComponents);
    ch.pipeline().addLast("aggregator", aggregator);
    if (transport.compression) {
        ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(transport.compressionLevel));
    }
    ch.pipeline().addLast("handler", new MainAndStaticFileHandler(
        nodeName,
        home,
        nodeClient,
        transport.getCorsConfig()
    ));
    pipelineRegistry.registerItems(ch.pipeline(), transport.getCorsConfig());
    if (SETTING_CORS_ENABLED.get(transport.settings())) {
        ch.pipeline().addAfter("encoder", "cors", new Netty4CorsHandler(transport.getCorsConfig()));
    }
}
 
Example #19
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #20
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #21
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #22
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #23
Source File: NettyServerUtil.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #25
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #26
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #27
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #28
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #29
Source File: NettyHttpClient.java    From jus with Apache License 2.0 5 votes vote down vote up
@Override public void prepare(final States.GenericState state) {
  this.concurrencyLevel = state.concurrencyLevel;
  this.targetBacklog = state.targetBacklog;

  ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() {
    @Override public void initChannel(SocketChannel channel) throws Exception {
      ChannelPipeline pipeline = channel.pipeline();

      if (state.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);
}
 
Example #30
Source File: SlackSenderInitializer.java    From SlackMC with MIT License 5 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    pipeline.addLast("codec", new HttpClientCodec());
    pipeline.addLast("inflater", new HttpContentDecompressor());
    pipeline.addLast("handler", new SlackSenderHandler(sender, webhookUrl, message));
}