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

项目:Camel    文件:HttpServerSharedInitializerFactory.java   
@Override
protected void initChannel(Channel ch) throws Exception {
    // create a new pipeline
    ChannelPipeline pipeline = ch.pipeline();

    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }

    pipeline.addLast("decoder", new HttpRequestDecoder(409, configuration.getMaxHeaderSize(), 8192));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    if (configuration.isChunked()) {
        pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
    }
    if (configuration.isCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }

    pipeline.addLast("handler", channelFactory.getChannelHandler());
}
项目:riposte    文件:HttpChannelInitializerTest.java   
@Test
public void initChannel_adds_HttpContentCompressor_before_HttpResponseEncoder_for_outbound_handler() {
    // given
    HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();

    // when
    hci.initChannel(socketChannelMock);

    // then
    ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
    verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
    List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
    Pair<Integer, HttpContentCompressor> httpContentCompressor = findChannelHandler(handlers, HttpContentCompressor.class);
    Pair<Integer, HttpResponseEncoder> httpResponseEncoder = findChannelHandler(handlers, HttpResponseEncoder.class);

    assertThat(httpContentCompressor, notNullValue());
    assertThat(httpResponseEncoder, notNullValue());

    // HttpContentCompressor's index should be later than HttpResponseEncoder's index to verify that it comes BEFORE HttpResponseEncoder on the OUTBOUND handlers
    // (since the outbound handlers are processed in reverse order).
    assertThat(httpContentCompressor.getLeft(), is(greaterThan(httpResponseEncoder.getLeft())));
}
项目:riposte    文件:HttpChannelInitializerTest.java   
@Test
public void initChannel_adds_RequestInfoSetterHandler_after_HttpContentCompressor() {
    // given
    HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();

    // when
    hci.initChannel(socketChannelMock);

    // then
    ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
    verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
    List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
    Pair<Integer, HttpContentCompressor> httpContentCompressor = findChannelHandler(handlers, HttpContentCompressor.class);
    Pair<Integer, RequestInfoSetterHandler> requestInfoSetterHandler = findChannelHandler(handlers, RequestInfoSetterHandler.class);

    assertThat(httpContentCompressor, notNullValue());
    assertThat(requestInfoSetterHandler, notNullValue());

    assertThat(requestInfoSetterHandler.getLeft(), is(greaterThan(httpContentCompressor.getLeft())));
    //verify max size is passed through into RequestInfoSetterHandler
    assertThat(extractField(requestInfoSetterHandler.getRight(), "globalConfiguredMaxRequestSizeInBytes"), is(42));
}
项目:JavaAyo    文件:HttpUploadServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpResponseEncoder());

    // Remove the following line if you don't want automatic content compression.
    pipeline.addLast(new HttpContentCompressor());

    pipeline.addLast(new HttpUploadServerHandler());
}
项目:netty-http-server    文件:ServerConfig.java   
@Bean(name = "channelInitializer")
public ChannelInitializer<SocketChannel> initializerFactory(final ApplicationContext contxt) {
    return new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            SimpleChannelInboundHandler<?> channelInboundHandler = contxt.getBean(NettyHttpChannelHandler.class);
            ChannelPipeline pipeline = ch.pipeline();
            // HTTP
            pipeline.addLast(new HttpRequestDecoder());
            pipeline.addLast(new HttpResponseEncoder());
            pipeline.addLast(new HttpContentCompressor());
            pipeline.addLast(new ChunkedWriteHandler());
            // 设置处理的Handler
            pipeline.addLast(channelInboundHandler);
        }
    };
}
项目:netty4.0.27Learn    文件:HttpUploadServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpResponseEncoder());

    // Remove the following line if you don't want automatic content compression.
    pipeline.addLast(new HttpContentCompressor());

    pipeline.addLast(new HttpUploadServerHandler());
}
项目:carbon-transports    文件:RedirectChannelInitializer.java   
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    // Add the generic handlers to the pipeline
    // e.g. SSL handler
    if (sslEngine != null) {
        if (log.isDebugEnabled()) {
            log.debug("adding ssl handler");
        }
        ch.pipeline().addLast("ssl", new SslHandler(this.sslEngine));
    }
    ch.pipeline().addLast("compressor", new HttpContentCompressor());
    ch.pipeline().addLast("decoder", new HttpResponseDecoder());
    ch.pipeline().addLast("encoder", new HttpRequestEncoder());
    if (httpTraceLogEnabled) {
        ch.pipeline().addLast(Constants.HTTP_TRACE_LOG_HANDLER,
                new HTTPTraceLoggingHandler("tracelog.http.upstream", LogLevel.DEBUG));
    }
    RedirectHandler redirectHandler = new RedirectHandler(sslEngine, httpTraceLogEnabled, maxRedirectCount
            , chunkDisabled, originalChannelContext, isIdleHandlerOfTargetChannelRemoved);
    ch.pipeline().addLast(Constants.REDIRECT_HANDLER, redirectHandler);
}
项目: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);

}
项目:netty.book.kor    文件:ApiServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }

    p.addLast(new HttpRequestDecoder());
    // Uncomment the following line if you don't want to handle HttpChunks.
    p.addLast(new HttpObjectAggregator(65536));
    p.addLast(new HttpResponseEncoder());
    // Remove the following line if you don't want automatic content
    // compression.
    p.addLast(new HttpContentCompressor());
    p.addLast(new ApiRequestParser());
}
项目:jaxrs-engine    文件:MicroServicesServerSC.java   
public void initChannel(SocketChannel channel) {
    ChannelPipeline pipeline = channel.pipeline();
    //        pipeline.addLast("tracker", connectionTracker);
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(Integer.MAX_VALUE));  //TODO: fix
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("compressor", new HttpContentCompressor());

    HttpResourceHandler resourceHandler = new HttpResourceHandler(dataHolder.getHttpServices(),
            new ArrayList<HandlerHook>(), null, null);
    pipeline.addLast(new DefaultEventExecutorGroup(200),
            "router", new RequestRouter(resourceHandler, 0)); //TODO: remove limit

    //TODO: see what can be done
    /*if (pipelineModifier != null) {
        pipelineModifier.apply(pipeline);
    }*/
}
项目:blade    文件:HttpServerInitializer.java   
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    if (enableGzip) {
        p.addLast(new HttpContentCompressor());
    }
    p.addLast(new HttpServerCodec(36192 * 2, 36192 * 8, 36192 * 16, false));
    p.addLast(new HttpServerExpectContinueHandler());
    p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
    p.addLast(new ChunkedWriteHandler());
    if (enableCors) {
        CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
        p.addLast(new CorsHandler(corsConfig));
    }
    if (null != blade.webSocketPath()) {
        p.addLast(new WebSocketServerProtocolHandler(blade.webSocketPath(), null, true));
        p.addLast(new WebSockerHandler(blade));
    }
    service.scheduleWithFixedDelay(() -> date = new AsciiString(DateKit.gmtDate(LocalDateTime.now())), 1000, 1000, TimeUnit.MILLISECONDS);
    p.addLast(new HttpServerHandler());
}
项目:tajo    文件:HttpDataServerChannelInitializer.java   
@Override
 protected void initChannel(Channel channel) throws Exception {
// Create a default pipeline implementation.
   ChannelPipeline pipeline = channel.pipeline();

   // Uncomment the following line if you want HTTPS
   // SSLEngine engine =
   // SecureChatSslContextFactory.getServerContext().createSSLEngine();
   // engine.setUseClientMode(false);
   // pipeline.addLast("ssl", new SslHandler(engine));

   pipeline.addLast("decoder", new HttpRequestDecoder());
   //pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
   pipeline.addLast("encoder", new HttpResponseEncoder());
   pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
   pipeline.addLast("deflater", new HttpContentCompressor());
   pipeline.addLast("handler", new HttpDataServerHandler(userName, appId));
 }
项目:netty4study    文件:HttpUploadServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();

    if (HttpUploadServer.isSSL) {
        SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
        engine.setUseClientMode(false);
        pipeline.addLast("ssl", new SslHandler(engine));
    }

    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());

    // Remove the following line if you don't want automatic content
    // compression.
    pipeline.addLast("deflater", new HttpContentCompressor());

    pipeline.addLast("handler", new HttpUploadServerHandler());
}
项目:ob1k    文件:NettyServer.java   
@Override
public void initChannel(final SocketChannel ch) throws Exception {
  final ChannelPipeline p = ch.pipeline();

  // Uncomment the following line if you want HTTPS
  //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
  //engine.setUseClientMode(false);
  //p.addLast("ssl", new SslHandler(engine));

  p.addLast("decoder", new HttpRequestDecoder(16384, 8192, 16384));
  p.addLast("encoder", new HttpResponseEncoder());
  p.addLast("aggregator", new HttpObjectAggregator(maxContentLength));

  p.addLast("chunkedWriter", new ChunkedWriteHandler());
  p.addLast("static", staticFileServerHandler);

  // the compressor is behind the static handler to avoid compression of static files
  // Netty doesn't handle it very well :(
  if (supportZip) {
    p.addLast("compressor", new HttpContentCompressor());
  }

  p.addLast("idleState", new IdleStateHandler(0, 0, idleTimeoutMs, TimeUnit.MILLISECONDS));
  p.addLast("handler", new HttpRequestDispatcherHandler(contextPath, dispatcher, staticResolver,
      marshallerRegistry, activeChannels, acceptKeepAlive, metricFactory, requestTimeoutMs));
}
项目: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);
    }
项目:jframe    文件:HttpServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    // p.addLast("log", new LoggingHandler(LogLevel.ERROR));

    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    p.addLast(new HttpRequestDecoder());
    p.addLast(new HttpResponseEncoder());
    p.addLast("http compressor", new HttpContentCompressor());
    // p.addLast(new HttpObjectAggregator(1048576));
    p.addLast("http dispatcher", reqDis);
    p.addLast("idleStateHandler", new IdleStateHandler(10, 10, 0));
    p.addLast("heartbeatHandler", new HeartbeatHandler());
}
项目:jframe    文件:HttpServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    // p.addLast("log", new LoggingHandler(LogLevel.ERROR));

    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    p.addLast(new HttpRequestDecoder());
    p.addLast(new HttpResponseEncoder());
    p.addLast("http compressor", new HttpContentCompressor());
    // p.addLast(new HttpObjectAggregator(1048576));
    p.addLast("http dispatcher", reqDis);
    p.addLast("idleStateHandler", new IdleStateHandler(30, 10, 0));
    p.addLast("heartbeatHandler", new HeartbeatHandler());
}
项目:netty-netty-5.0.0.Alpha1    文件:HttpUploadServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();

    if (HttpUploadServer.isSSL) {
        SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
        engine.setUseClientMode(false);
        pipeline.addLast("ssl", new SslHandler(engine));
    }

    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());

    // Remove the following line if you don't want automatic content
    // compression.
    pipeline.addLast("deflater", new HttpContentCompressor());

    pipeline.addLast("handler", new HttpUploadServerHandler());
}
项目:laputa    文件:LaputaServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
  ChannelPipeline p = ch.pipeline();
  p.addLast(new ReadTimeoutHandler(60, TimeUnit.SECONDS));
  if (sslContext != null) {
    p.addLast(sslContext.newHandler(ch.alloc()));
  }
  p.addLast(new HttpContentCompressor(5));
  p.addLast(new HttpServerCodec());
  p.addLast(new HttpObjectAggregator(1048576));
  p.addLast(new ChunkedWriteHandler());
  if (null != corsConfig) {
    p.addLast(new CorsHandler(corsConfig));
  }
  p.addLast(new WebSocketServerCompressionHandler());
  p.addLast(new WebSocketServerProtocolHandler(webSocketPath, null, true));
  p.addLast(new LaputaServerHandler(null != sslContext, requestProcessor));
}
项目:redant    文件:MasterServer.java   
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpContentCompressor());
    pipeline.addLast(new HttpObjectAggregator(CommonConstants.MAX_CONTENT_LENGTH));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new MasterProxyHandler());
}
项目: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());
            }
        };
    }
项目:kurdran    文件:NettyHandlerInitializer.java   
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline cp = socketChannel.pipeline();
    cp.addLast(new HttpServerCodec());  //添加服务端http编、解码器
    cp.addLast(new HttpObjectAggregator(512*1024));  //http消息聚合
    cp.addLast(new HttpContentCompressor());   //开启压缩
    cp.addLast(new HttpServerHandler(kurdran));
}
项目:twill    文件:TrackerService.java   
@Override
protected void startUp() throws Exception {
  channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
  EventLoopGroup bossGroup = new NioEventLoopGroup(NUM_BOSS_THREADS,
                                                   new ThreadFactoryBuilder()
                                                     .setDaemon(true).setNameFormat("boss-thread").build());
  EventLoopGroup workerGroup = new NioEventLoopGroup(NUM_WORKER_THREADS,
                                                     new ThreadFactoryBuilder()
                                                       .setDaemon(true).setNameFormat("worker-thread#%d").build());

  bootstrap = new ServerBootstrap()
    .group(bossGroup, workerGroup)
    .channel(NioServerSocketChannel.class)
    .childHandler(new ChannelInitializer<SocketChannel>() {
      @Override
      protected void initChannel(SocketChannel ch) throws Exception {
        channelGroup.add(ch);
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast("codec", new HttpServerCodec());
        pipeline.addLast("compressor", new HttpContentCompressor());
        pipeline.addLast("aggregator", new HttpObjectAggregator(MAX_INPUT_SIZE));
        pipeline.addLast("handler", new ReportHandler());
      }
    });

  Channel serverChannel = bootstrap.bind(new InetSocketAddress(host, 0)).sync().channel();
  channelGroup.add(serverChannel);

  bindAddress = (InetSocketAddress) serverChannel.localAddress();
  url = URI.create(String.format("http://%s:%d", host, bindAddress.getPort())).toURL();

  LOG.info("Tracker service started at {}", url);
}
项目:lannister    文件:WebServerChannelInitializer.java   
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    if ("true".equalsIgnoreCase(Settings.INSTANCE.getProperty("webserver.logging.writelogOfNettyLogger"))) {
        ch.pipeline().addLast("log", new LoggingHandler("lannister.web/server", LogLevel.DEBUG));
    }

    if (useSsl) {
        SslContext sslCtx = SslContextBuilder
                .forServer(Settings.INSTANCE.certChainFile(), Settings.INSTANCE.privateKeyFile()).build();

        logger.debug("SSL Provider : {}", SslContext.defaultServerProvider());

        ch.pipeline().addLast(sslCtx.newHandler(ch.alloc()));
    }

    ch.pipeline().addLast(HttpServerCodec.class.getName(), new HttpServerCodec());
    ch.pipeline().addLast(HttpObjectAggregator.class.getName(), new HttpObjectAggregator(1048576));
    ch.pipeline().addLast(HttpContentCompressor.class.getName(), new HttpContentCompressor());
    ch.pipeline().addLast(HttpRequestRouter.class.getName(), new HttpRequestRouter());

    if (websocketFrameHandlerClass != null) {
        WebsocketFrameHandler wsfh = websocketFrameHandlerClass.newInstance();

        ch.pipeline().addLast(WebSocketServerProtocolHandler.class.getName(), new WebSocketServerProtocolHandler(
                wsfh.websocketPath(), wsfh.subprotocols(), wsfh.allowExtensions(), wsfh.maxFrameSize()));

        ch.pipeline().addLast(wsfh);
    }
}
项目: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    文件:HTTPJsonWriter.java   
@Override
protected void initChannel(final NioSocketChannel ch) throws Exception {
    final ChannelPipeline p = ch.pipeline();
    if(compressionEnabled) p.addLast("deflater", new HttpContentCompressor());
    p.addLast("decoder", new HttpRequestDecoder());         
    p.addLast("encoder", new HttpResponseEncoder());
    if(chunkingEnabled) p.addLast("chunker", new ChunkedWriteHandler());    
    p.addLast("httpRequestConverter", METRIC_HTTP_ENCODER);
    p.addLast("metricEncoder", METRIC_ENCODER);
    p.addLast("responseHandler", RESPONSE_HANDLER);
}
项目:byproxy    文件:HttpMatcher.java   
@Override
public void handlePipeline(ChannelPipeline pipeline) {
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpServerExpectContinueHandler());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new HttpContentCompressor());
    pipeline.addLast(new HttpRequestHandler(sslContextManager));
}
项目:JavaAyo    文件:PortUnificationServerHandler.java   
private void switchToHttp(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast("decoder", new HttpRequestDecoder());
    p.addLast("encoder", new HttpResponseEncoder());
    p.addLast("deflater", new HttpContentCompressor());
    p.addLast("handler", new HttpSnoopServerHandler());
    p.remove(this);
}
项目:QuestionReg    文件:HttpServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpResponseEncoder());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new HttpContentCompressor());
    pipeline.addLast(new HttpServerHandler(mainPool));  
}
项目:netty4.0.27Learn    文件:PortUnificationServerHandler.java   
private void switchToHttp(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast("decoder", new HttpRequestDecoder());
    p.addLast("encoder", new HttpResponseEncoder());
    p.addLast("deflater", new HttpContentCompressor());
    p.addLast("handler", new HttpSnoopServerHandler());
    p.remove(this);
}
项目:lambdatra    文件:NettyInitializer.java   
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ch.pipeline()
        .addLast(new HttpServerCodec())
        .addLast(new HttpObjectAggregator(MAX_BODY_SIZE))
        .addLast(new HttpContentCompressor())
        .addLast(new NettyHandler(router));
}
项目:carbon-transports    文件:HTTPProtocolNegotiationHandler.java   
@Override
/**
 *  Configure pipeline after SSL handshake
 */
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
    ChannelPipeline p = ctx.pipeline();
    // handles pipeline for HTTP/2 requests after SSL handshake
    if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
        ctx.pipeline().addLast("http2-handler", new HTTP2SourceHandlerBuilder(connectionManager,
                listenerConfiguration).build());
        return;
    }
    // handles pipeline for HTTP/1 requests after SSL handshake
    if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
        p.addLast("encoder", new HttpResponseEncoder());
        if (requestSizeValidationConfig.isHeaderSizeValidation()) {
            p.addLast("decoder", new CustomHttpRequestDecoder(requestSizeValidationConfig));
        } else {
            p.addLast("decoder", new HttpRequestDecoder());
        }
        if (requestSizeValidationConfig.isRequestSizeValidation()) {
            p.addLast("custom-aggregator", new CustomHttpObjectAggregator(requestSizeValidationConfig));
        }
        p.addLast("compressor", new HttpContentCompressor());
        p.addLast("chunkWriter", new ChunkedWriteHandler());
        try {
            // TODO: Properly fix this part once we start HTTP2 integration
            p.addLast("handler", new SourceHandler(
                    new HttpWsServerConnectorFuture(null), null));
        } catch (Exception e) {
            log.error("Cannot Create SourceHandler ", e);
        }
        return;
    }

    throw new IllegalStateException("unknown protocol: " + protocol);
}
项目:javase-study    文件:PortUnificationServerHandler.java   
private void switchToHttp(ChannelHandlerContext ctx) {
        ChannelPipeline pipeline = ctx.pipeline();
        pipeline.addLast("decoder", new HttpRequestDecoder());
        pipeline.addLast("encoder", new HttpResponseEncoder());
        pipeline.addLast("deflater", new HttpContentCompressor());
//        pipeline.addLast("handler", new HttpSnoo)

        pipeline.remove(this);
    }
项目:netty4study    文件:PortUnificationServerHandler.java   
private void switchToHttp(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast("decoder", new HttpRequestDecoder());
    p.addLast("encoder", new HttpResponseEncoder());
    p.addLast("deflater", new HttpContentCompressor());
    p.addLast("handler", new HttpSnoopServerHandler());
    p.remove(this);
}
项目:disthene-reader    文件:ReaderServer.java   
public void run() throws InterruptedException {
    bossGroup = new NioEventLoopGroup(configuration.getThreads());
    workerGroup = new NioEventLoopGroup(configuration.getThreads());

    ServerBootstrap b = new ServerBootstrap();

    b.group(bossGroup, workerGroup)
            .channel(NioServerSocketChannel.class)
            .option(ChannelOption.SO_BACKLOG, 100)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline p = ch.pipeline();
                    p.addLast(new HttpRequestDecoder(
          configuration.getMaxInitialLineLength(),
                        configuration.getMaxHeaderSize(),
   configuration.getMaxChunkSize()
                ));
                    p.addLast(new HttpObjectAggregator(MAX_CONTENT_LENGTH));
                    p.addLast(new HttpResponseEncoder());
                    p.addLast(new HttpContentCompressor());
                    p.addLast(new ReaderServerHandler(handlers));
                }

                @Override
                public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
                    logger.error(cause);
                    super.exceptionCaught(ctx, cause);
                }
            });

    // Start the server.
    b.bind(configuration.getBind(), configuration.getPort()).sync();
}
项目:distributeTemplate    文件:HttpUploadServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();


    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());

    // Remove the following line if you don't want automatic content
    // compression.
    pipeline.addLast("deflater", new HttpContentCompressor());

    pipeline.addLast("handler", new HttpUploadServerHandler(node));
}
项目:modules-extra    文件:ApiServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception
{
    ch.pipeline()
        .addLast("ipfilter", new IpFilter(server))
        .addLast("iplimiter", new IpLimiter(server.getMaxConnectionCount()))
        .addLast("decoder", new HttpRequestDecoder())
        .addLast("aggregator", new HttpObjectAggregator(this.server.getMaxContentLength()))
        .addLast("encoder", new HttpResponseEncoder())
        .addLast("httpHandler", new HttpRequestHandler(cm, am, this.server, this.objectMapper));
    if (this.server.isCompressionEnabled())
    {
        ch.pipeline().addLast("deflater", new HttpContentCompressor(this.server.getCompressionLevel(), this.server.getCompressionWindowBits(), this.server.getCompressionMemoryLevel()));
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:PortUnificationServerHandler.java   
private void switchToHttp(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast("decoder", new HttpRequestDecoder());
    p.addLast("encoder", new HttpResponseEncoder());
    p.addLast("deflater", new HttpContentCompressor());
    p.addLast("handler", new HttpSnoopServerHandler());
    p.remove(this);
}
项目:liveoak    文件:PipelineConfigurator.java   
public void switchToPlainHttp(ChannelPipeline pipeline) {
    // turn off automatic socket read for better http body read control
    pipeline.addLast("channel-resetter", new ChannelResetterHandler(this));
    pipeline.channel().config().setAutoRead(false);
    pipeline.remove(WebSocketHandshakerHandler.class);
    //pipeline.addLast(new DebugHandler("server-pre-cors"));
    pipeline.addLast("cors-origin-handler", new CORSHandler());
    pipeline.addLast("cors-preflight-handler", new CORSPreflightOptionsHandler());
    //pipeline.addLast( new DebugHandler( "server-post-cors" ) );

    pipeline.addLast("deflater", new HttpContentCompressor(1));

    pipeline.addLast("http-resource-decoder", new HttpResourceRequestDecoder(this.codecManager));
    pipeline.addLast("http-resource-encoder", new HttpResourceResponseEncoder(this.codecManager));
    pipeline.addLast("http-request-body-handler", new HttpRequestBodyHandler());
    pipeline.addLast("interceptor", new InterceptorHandler("http", this.interceptorManager));
    pipeline.addLast("request-context-disposer", new RequestContextDisposerHandler());

    //pipeline.addLast("auth-handler", new AuthHandler(this.client));
    //pipeline.addLast("authz-handler", new AuthzHandler(this.client));

    pipeline.addLast("subscription-watcher", new SubscriptionWatcher(this.subscriptionManager));
    //pipeline.addLast( new DebugHandler( "server-debug" ) );
    pipeline.addLast("resource-state-handler", new ResourceStateHandler(this.workerPool));
    pipeline.addLast("object-handler", new ResourceHandler(this.globalContext, this.workerPool));
    pipeline.addLast("error-handler", new ErrorHandler());
}