use of io.netty.handler.codec.http.HttpContentDecompressor in project proxyee-down by monkeyWie.
the class ResponseTextIntercept method afterResponse.
@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();
}
httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html;charset=utf-8");
// 直接调用默认拦截器,跳过下载拦截器
pipeline.getDefault().afterResponse(clientChannel, proxyChannel, httpResponse, pipeline);
} else {
isMatch = false;
pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
}
}
use of io.netty.handler.codec.http.HttpContentDecompressor in project tesla by linking12.
the class ProxyConnection method aggregateContentForFiltering.
public void aggregateContentForFiltering(ChannelPipeline pipeline, int numberOfBytesToBuffer) {
pipeline.addLast("inflater", new HttpContentDecompressor());
pipeline.addLast("aggregator", new HttpObjectAggregator(numberOfBytesToBuffer));
}
use of io.netty.handler.codec.http.HttpContentDecompressor in project netty by netty.
the class HttpSnoopClientInitializer method initChannel.
@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());
}
use of io.netty.handler.codec.http.HttpContentDecompressor in project okhttp by square.
the class NettyHttpClient method prepare.
@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);
}
use of io.netty.handler.codec.http.HttpContentDecompressor in project reactor-netty by reactor.
the class HttpClientTest method gzip.
@Test
public void gzip() {
String content = "HELLO WORLD";
NettyContext c = HttpServer.create(opts -> opts.compression(true).port(0)).newHandler((req, res) -> res.sendString(Mono.just(content))).block();
// verify gzip is negotiated (when no decoder)
StepVerifier.create(HttpClient.create(c.address().getPort()).get("/", req -> req.followRedirect().addHeader("Accept-Encoding", "gzip").addHeader("Accept-Encoding", "deflate")).flatMap(r -> r.receive().aggregate().asString().zipWith(Mono.just(r.responseHeaders().get("Content-Encoding", ""))).zipWith(Mono.just(r)))).expectNextMatches(tuple -> {
return !tuple.getT1().getT1().equals(content) && "gzip".equals(tuple.getT1().getT2());
}).expectComplete().verify();
// verify decoder does its job and removes the header
StepVerifier.create(HttpClient.create(c.address().getPort()).get("/", req -> {
req.context().addHandlerFirst("gzipDecompressor", new HttpContentDecompressor());
return req.followRedirect().addHeader("Accept-Encoding", "gzip").addHeader("Accept-Encoding", "deflate");
}).flatMap(r -> r.receive().aggregate().asString().zipWith(Mono.just(r.responseHeaders().get("Content-Encoding", ""))).zipWith(Mono.just(r)))).expectNextMatches(tuple -> {
return tuple.getT1().getT1().equals(content) && "".equals(tuple.getT1().getT2());
}).expectComplete().verify();
c.dispose();
}
Aggregations