Search in sources :

Example 26 with ChunkedWriteHandler

use of io.netty.handler.stream.ChunkedWriteHandler in project netty by netty.

the class HttpStaticFileServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new HttpStaticFileServerHandler());
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 27 with ChunkedWriteHandler

use of io.netty.handler.stream.ChunkedWriteHandler in project netty by netty.

the class Http2StaticFileServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    pipeline.addLast(Http2FrameCodecBuilder.forServer().build());
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new Http2StaticFileServerHandler());
}
Also used : ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 28 with ChunkedWriteHandler

use of io.netty.handler.stream.ChunkedWriteHandler in project vert.x by eclipse.

the class HttpServerWorker method configureHttp1OrH2C.

private void configureHttp1OrH2C(ChannelPipeline pipeline) {
    if (logEnabled) {
        pipeline.addLast("logging", new LoggingHandler(options.getActivityLogDataFormat()));
    }
    if (HttpServerImpl.USE_FLASH_POLICY_HANDLER) {
        pipeline.addLast("flashpolicy", new FlashPolicyHandler());
    }
    pipeline.addLast("httpDecoder", new VertxHttpRequestDecoder(options));
    pipeline.addLast("httpEncoder", new VertxHttpResponseEncoder());
    if (options.isDecompressionSupported()) {
        pipeline.addLast("inflater", new HttpContentDecompressor(false));
    }
    if (options.isCompressionSupported()) {
        pipeline.addLast("deflater", new HttpChunkContentCompressor(options.getCompressionLevel()));
    }
    if (sslHelper.isSSL() || options.isCompressionSupported()) {
        // only add ChunkedWriteHandler when SSL is enabled otherwise it is not needed as FileRegion is used.
        // For large file / sendfile support
        pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    }
    int idleTimeout = options.getIdleTimeout();
    int readIdleTimeout = options.getReadIdleTimeout();
    int writeIdleTimeout = options.getWriteIdleTimeout();
    if (idleTimeout > 0 || readIdleTimeout > 0 || writeIdleTimeout > 0) {
        pipeline.addLast("idle", new IdleStateHandler(readIdleTimeout, writeIdleTimeout, idleTimeout, options.getIdleTimeoutUnit()));
    }
    if (disableH2C) {
        configureHttp1(pipeline);
    } else {
        pipeline.addLast("h2c", new Http1xUpgradeToH2CHandler(this, options.isCompressionSupported(), options.isDecompressionSupported()));
    }
}
Also used : FlashPolicyHandler(io.vertx.core.http.impl.cgbystrom.FlashPolicyHandler) LoggingHandler(io.netty.handler.logging.LoggingHandler) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor)

Example 29 with ChunkedWriteHandler

use of io.netty.handler.stream.ChunkedWriteHandler in project hive by apache.

the class ShuffleHandler method initPipeline.

private void initPipeline(ServerBootstrap bootstrap, Configuration conf) throws Exception {
    SHUFFLE = getShuffle(conf);
    // TODO Setup SSL Shuffle
    // if (conf.getBoolean(MRConfig.SHUFFLE_SSL_ENABLED_KEY,
    // MRConfig.SHUFFLE_SSL_ENABLED_DEFAULT)) {
    // LOG.info("Encrypted shuffle is enabled.");
    // sslFactory = new SSLFactory(SSLFactory.Mode.SERVER, conf);
    // sslFactory.init();
    // }
    ChannelInitializer<NioSocketChannel> channelInitializer = new ChannelInitializer<NioSocketChannel>() {

        @Override
        public void initChannel(NioSocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            if (sslFactory != null) {
                pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
            }
            pipeline.addLast("decoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpObjectAggregator(1 << 16));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("chunking", new ChunkedWriteHandler());
            pipeline.addLast("shuffle", SHUFFLE);
            pipeline.addLast("idle", new IdleStateHandler(0, connectionKeepAliveTimeOut, 0));
            pipeline.addLast(TIMEOUT_HANDLER, new TimeoutHandler());
        }
    };
    bootstrap.childHandler(channelInitializer);
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 30 with ChunkedWriteHandler

use of io.netty.handler.stream.ChunkedWriteHandler in project jersey by jersey.

the class JerseyServerInitializer method configureClearText.

/**
     * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.
     */
private void configureClearText(SocketChannel ch) {
    final ChannelPipeline p = ch.pipeline();
    final HttpServerCodec sourceCodec = new HttpServerCodec();
    p.addLast(sourceCodec);
    p.addLast(new HttpServerUpgradeHandler(sourceCodec, new HttpServerUpgradeHandler.UpgradeCodecFactory() {

        @Override
        public HttpServerUpgradeHandler.UpgradeCodec newUpgradeCodec(CharSequence protocol) {
            if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
                return new Http2ServerUpgradeCodec(new Http2Codec(true, new JerseyHttp2ServerHandler(baseUri, container)));
            } else {
                return null;
            }
        }
    }));
    p.addLast(new SimpleChannelInboundHandler<HttpMessage>() {

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
            // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP.
            // "Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)");
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null, new JerseyServerHandler(baseUri, container));
            pipeline.replace(this, null, new ChunkedWriteHandler());
            ctx.fireChannelRead(msg);
        }
    });
}
Also used : Http2ServerUpgradeCodec(io.netty.handler.codec.http2.Http2ServerUpgradeCodec) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) Http2Codec(io.netty.handler.codec.http2.Http2Codec) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Aggregations

ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)57 ChannelPipeline (io.netty.channel.ChannelPipeline)28 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)18 SslHandler (io.netty.handler.ssl.SslHandler)13 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)12 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)12 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)11 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)11 ByteBuf (io.netty.buffer.ByteBuf)10 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)10 LoggingHandler (io.netty.handler.logging.LoggingHandler)10 SocketChannel (io.netty.channel.socket.SocketChannel)8 ChannelFuture (io.netty.channel.ChannelFuture)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)6 Test (org.junit.Test)6 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)5 SslContext (io.netty.handler.ssl.SslContext)5 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)4