Search in sources :

Example 1 with HttpContentCompressor

use of io.netty.handler.codec.http.HttpContentCompressor in project netty by netty.

the class PortUnificationServerHandler method switchToHttp.

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);
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(io.netty.handler.codec.http.HttpContentCompressor) HttpSnoopServerHandler(io.netty.example.http.snoop.HttpSnoopServerHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 2 with HttpContentCompressor

use of io.netty.handler.codec.http.HttpContentCompressor in project camel by apache.

the class HttpServerSharedInitializerFactory method initChannel.

@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());
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(io.netty.handler.codec.http.HttpContentCompressor) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 3 with HttpContentCompressor

use of io.netty.handler.codec.http.HttpContentCompressor in project netty by netty.

the class HttpUploadServerInitializer method initChannel.

@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());
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(io.netty.handler.codec.http.HttpContentCompressor) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 4 with HttpContentCompressor

use of io.netty.handler.codec.http.HttpContentCompressor in project camel by apache.

the class HttpServerInitializerFactory method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    // create a new pipeline
    ChannelPipeline pipeline = ch.pipeline();
    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        //TODO must close on SSL exception
        // sslHandler.setCloseOnSSLException(true);
        LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }
    pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
    List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
    for (int x = 0; x < decoders.size(); x++) {
        ChannelHandler decoder = decoders.get(x);
        if (decoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
        }
        pipeline.addLast("decoder-" + x, decoder);
    }
    pipeline.addLast("encoder", new HttpResponseEncoder());
    List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
    for (int x = 0; x < encoders.size(); x++) {
        ChannelHandler encoder = encoders.get(x);
        if (encoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
        }
        pipeline.addLast("encoder-" + x, encoder);
    }
    pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
    if (supportCompressed()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }
    int port = consumer.getConfiguration().getPort();
    ChannelHandler handler = consumer.getEndpoint().getComponent().getMultiplexChannelHandler(port).getChannelHandler();
    if (consumer.getConfiguration().isUsingExecutorService()) {
        EventExecutorGroup applicationExecutor = consumer.getEndpoint().getComponent().getExecutorService();
        pipeline.addLast(applicationExecutor, "handler", handler);
    } else {
        pipeline.addLast("handler", handler);
    }
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChannelHandlerFactory(org.apache.camel.component.netty4.ChannelHandlerFactory) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(io.netty.handler.codec.http.HttpContentCompressor) ChannelHandler(io.netty.channel.ChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 5 with HttpContentCompressor

use of io.netty.handler.codec.http.HttpContentCompressor in project netty-socketio by mrniko.

the class SocketIOChannelInitializer method addSocketioHandlers.

/**
     * Adds the socketio channel handlers
     *
     * @param pipeline
     */
protected void addSocketioHandlers(ChannelPipeline pipeline) {
    pipeline.addLast(HTTP_REQUEST_DECODER, new HttpRequestDecoder());
    pipeline.addLast(HTTP_AGGREGATOR, new HttpObjectAggregator(configuration.getMaxHttpContentLength()) {

        @Override
        protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) {
            return null;
        }
    });
    pipeline.addLast(HTTP_ENCODER, new HttpResponseEncoder());
    if (configuration.isHttpCompression()) {
        pipeline.addLast(HTTP_COMPRESSION, new HttpContentCompressor());
    }
    pipeline.addLast(PACKET_HANDLER, packetHandler);
    pipeline.addLast(AUTHORIZE_HANDLER, authorizeHandler);
    pipeline.addLast(XHR_POLLING_TRANSPORT, xhrPollingTransport);
    // TODO use single instance when https://github.com/netty/netty/issues/4755 will be resolved
    if (configuration.isWebsocketCompression()) {
        pipeline.addLast(WEB_SOCKET_TRANSPORT_COMPRESSION, new WebSocketServerCompressionHandler());
    }
    pipeline.addLast(WEB_SOCKET_TRANSPORT, webSocketTransport);
    pipeline.addLast(SOCKETIO_ENCODER, encoderHandler);
    pipeline.addLast(WRONG_URL_HANDLER, wrongUrlHandler);
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(io.netty.handler.codec.http.HttpContentCompressor) WebSocketServerCompressionHandler(io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler) HttpMessage(io.netty.handler.codec.http.HttpMessage) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)6 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)6 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)6 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)6 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)3 SslHandler (io.netty.handler.ssl.SslHandler)2 InternalErrorException (com.cloud.exception.InternalErrorException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelHandler (io.netty.channel.ChannelHandler)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 HttpSnoopServerHandler (io.netty.example.http.snoop.HttpSnoopServerHandler)1 HttpMessage (io.netty.handler.codec.http.HttpMessage)1 WebSocketServerCompressionHandler (io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1