Java 类io.netty.handler.codec.http.HttpContentDecompressor 实例源码

项目:onedatashare    文件:HTTPInitializer.java   
/**
 * 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));
}
项目:Stork    文件:HTTPInitializer.java   
/**
 * 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));
}
项目:ServiceCOLDCache    文件:HttpSnoopClientInitializer.java   
@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());
    }
项目:JavaAyo    文件:HttpUploadClientIntializer.java   
@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());
}
项目:JavaAyo    文件:HttpSnoopClientInitializer.java   
@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());
}
项目:SI    文件:HttpClientInitializer.java   
@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));
    }
项目:GameServerFramework    文件:NHttpRequest.java   
@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());
}
项目:netty4.0.27Learn    文件:HttpUploadClientIntializer.java   
@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());
}
项目:netty4.0.27Learn    文件:HttpSnoopClientInitializer.java   
@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());
}
项目:gale    文件:GaleServerInitializer.java   
@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);

}
项目:SI    文件:HttpClientInitializer.java   
@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));
    }
项目:KIARA    文件:URILoader.java   
@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);
}
项目:netty4study    文件:HttpUploadClientIntializer.java   
@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());
}
项目:netty4study    文件:HttpSnoopClientInitializer.java   
@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());
}
项目:jus    文件:NettyClientInit.java   
@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);
}
项目:kha    文件:ApiServerChannelInitializer.java   
@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);
    }
项目:netty-netty-5.0.0.Alpha1    文件:HttpUploadClientIntializer.java   
@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());
}
项目:netty-netty-5.0.0.Alpha1    文件:HttpSnoopClientInitializer.java   
@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());
}
项目:mockserver    文件:PortUnificationHandler.java   
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);
}
项目:stork    文件:HTTPInitializer.java   
/**
 * 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));
}
项目:GitHub    文件:NettyHttpClient.java   
@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);
}
项目:GitHub    文件:NettyHttpClient.java   
@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);
}
项目:elasticsearch_my    文件:Netty4HttpServerTransport.java   
@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);
}
项目:qonduit    文件:Server.java   
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());
            }
        };
    }
项目:qonduit    文件:TestServer.java   
@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);
        }
    };
}
项目:proxyee-down    文件:ResponseTextIntercept.java   
@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);
  }
}
项目:PriorityOkHttp    文件:NettyHttpClient.java   
@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);
}
项目:Okhttp    文件:NettyHttpClient.java   
@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);
}
项目:timely    文件:TestServer.java   
@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);
        }
    };
}
项目:megaphone    文件:ChannelManager.java   
private HttpContentDecompressor newHttpContentDecompressor() {
    if (config.isKeepEncodingHeader())
        return new HttpContentDecompressor() {
            @Override
            protected String getTargetContentEncoding(String contentEncoding) throws Exception {
                return contentEncoding;
            }
        };
    else
        return new HttpContentDecompressor();
}
项目:HeliosStreams    文件:ConnectionManager.java   
@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));
}
项目:HeliosStreams    文件:PipelineFactory.java   
/**
 * 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);
}
项目:HeliosStreams    文件:HubManager.java   
@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);
        }
项目:HeliosStreams    文件:HubManager.java   
/**
     * {@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);

    }
项目:reactor-netty    文件:HttpClient.java   
@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());
    }
}
项目:little_mitm    文件:NettyClient_NoHttps.java   
@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);
}
项目:Camel    文件:NettyHttpCompressTest.java   
@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;
}
项目:netty-cookbook    文件:BootstrapTemplate.java   
@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);
}
项目:netty-cookbook    文件:BootstrapTemplate.java   
@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);
}
项目:netty-cookbook    文件:BootstrapTemplate.java   
@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);
}