Example usage for io.netty.handler.codec.http HttpServerCodec HttpServerCodec

List of usage examples for io.netty.handler.codec.http HttpServerCodec HttpServerCodec

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpServerCodec HttpServerCodec.

Prototype

public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) 

Source Link

Document

Creates a new instance with the specified decoder options.

Usage

From source file:com.aerofs.baseline.http.AcceptedChannelInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel channel) throws Exception {
    LOGGER.trace("{}: setup", Channels.getHexText(channel));

    // time how long channels live
    channel.closeFuture().addListener(new GenericFutureListener<Future<Void>>() {

        private final Timer.Context lifetimeContext = CHANNEL_LIFETIME_TIMER.time();

        @Override/*from  w  w  w  .  j  a  v a2s  . c  o m*/
        public void operationComplete(Future<Void> future) throws Exception {
            lifetimeContext.stop();
        }
    });

    // create the channel pipeline
    channel.pipeline().addLast(new IdleTimeoutHandler(0, 0, (int) http.getIdleTimeout(), TimeUnit.MILLISECONDS),
            new HttpServerCodec(HTTP_MAX_INITIAL_LINE_LENGTH, HTTP_MAX_HEADER_SIZE, HTTP_MAX_CHUNK_SIZE, false),
            requestHeaderAssigner, new BufferingHttpObjectHandler(),
            new HttpRequestHandler(applicationHandler, baseUri, applicationExecutor, timer),
            finalInboundHandler);
}

From source file:com.netty.HttpHelloWorldServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();/*w  w  w.  j  av  a 2 s.  c  om*/
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    //        p.addLast(new HttpServerCodec(4096, 8192, 8192, false));
    p.addLast(new HttpServerCodec(4096, 8192, 8192, false));
    p.addLast("decompressor", new HttpContentDecompressor());
    p.addLast("aggegator", new HttpObjectAggregator(512 * 1024));
    //        p.addLast(new HttpAggregatorInitializer(false));
    ServerBaseHandler channelHandler = applicationContext.getBean(ServerBaseHandler.class);
    channelHandler.setApplicationContext(applicationContext);
    //        p.addLast(new HttpHelloWorldServerHandler());
    p.addLast(channelHandler);
    p.addLast(new HttpContentCompressor());
}

From source file:com.vmware.xenon.common.http.netty.NettyHttpServerInitializer.java

License:Open Source License

/**
 * initChannel is called by Netty when a channel is first used.
 *//*from   w w w.  j a  v a  2s.c  o m*/
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    ch.config().setAllocator(NettyChannelContext.ALLOCATOR);
    ch.config().setSendBufferSize(NettyChannelContext.BUFFER_SIZE);
    ch.config().setReceiveBufferSize(NettyChannelContext.BUFFER_SIZE);

    SslHandler sslHandler = null;
    if (this.sslContext != null) {
        sslHandler = this.sslContext.newHandler(ch.alloc());
        SslClientAuthMode mode = this.host.getState().sslClientAuthMode;
        if (mode != null) {
            switch (mode) {
            case NEED:
                sslHandler.engine().setNeedClientAuth(true);
                break;
            case WANT:
                sslHandler.engine().setWantClientAuth(true);
                break;
            default:
                break;
            }
        }
        p.addLast(SSL_HANDLER, sslHandler);
    }

    // The HttpServerCodec combines the HttpRequestDecoder and the HttpResponseEncoder, and it
    // also provides a method for upgrading the protocol, which we use to support HTTP/2. It
    // also supports a couple other minor features (support for HEAD and CONNECT), which
    // probably don't matter to us.
    HttpServerCodec http1_codec = new HttpServerCodec(NettyChannelContext.MAX_INITIAL_LINE_LENGTH,
            NettyChannelContext.MAX_HEADER_SIZE, NettyChannelContext.MAX_CHUNK_SIZE, false);
    p.addLast(HTTP1_CODEC, http1_codec);
    if (this.sslContext == null) {
        // Today we only use HTTP/2 when SSL is disabled
        final HttpToHttp2ConnectionHandler connectionHandler = makeHttp2ConnectionHandler();
        UpgradeCodecFactory upgradeCodecFactory = new UpgradeCodecFactory() {
            @Override
            public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
                if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
                    return new Http2ServerUpgradeCodec(connectionHandler);
                } else {
                    return null;
                }
            }
        };
        // On upgrade, the upgradeHandler will remove the http1_codec and replace it
        // with the connectionHandler. Ideally we'd remove the aggregator (chunked transfer
        // isn't allowed in HTTP/2) and the WebSocket handler (we don't support it over HTTP/2 yet)
        // but we're not doing that yet.

        HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(http1_codec,
                upgradeCodecFactory);

        p.addLast(HTTP2_UPGRADE_HANDLER, upgradeHandler);
    }

    p.addLast(AGGREGATOR_HANDLER, new HttpObjectAggregator(this.responsePayloadSizeLimit));
    p.addLast(WEBSOCKET_HANDLER, new NettyWebSocketRequestHandler(this.host,
            ServiceUriPaths.CORE_WEB_SOCKET_ENDPOINT, ServiceUriPaths.WEB_SOCKET_SERVICE_PREFIX));
    p.addLast(HTTP_REQUEST_HANDLER,
            new NettyHttpClientRequestHandler(this.host, sslHandler, this.responsePayloadSizeLimit));
}

From source file:io.nebo.container.NettyEmbeddedServletInitializer.java

License:Apache License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();//from   w  w  w  .ja va  2  s  . c om
    p.addLast("codec", new HttpServerCodec(4096, 8192, 8192, false));
    p.addLast("servletInput", new ServletContentHandler(servletContext, p.channel()));
    p.addLast(servletExecutor, "filterChain", requestDispatcherHandler);
}

From source file:org.jooby.internal.netty.NettyPipeline.java

License:Apache License

private HttpServerCodec http1Codec() {
    return new HttpServerCodec(maxInitialLineLength, maxHeaderSize, maxChunkSize, false);
}

From source file:org.springframework.boot.context.embedded.netty.NettyEmbeddedServletInitializer.java

License:Apache License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();// w w w  . j  a  v a 2  s  .c o m
    p.addLast("codec", new HttpServerCodec(4096, 8192, 8192, false));
    p.addLast("servletInput", new ServletContentHandler(servletContext));
    p.addLast(servletExecutor, "filterChain", requestDispatcherHandler);
}