Search in sources :

Example 1 with HttpServerExpectContinueHandler

use of io.netty.handler.codec.http.HttpServerExpectContinueHandler in project cdap by caskdata.

the class NettyRouter method createServerBootstrap.

private ServerBootstrap createServerBootstrap(final ChannelGroup channelGroup) throws ServiceBindException {
    EventLoopGroup bossGroup = createEventLoopGroup(serverBossThreadPoolSize, "router-server-boss-thread-%d");
    EventLoopGroup workerGroup = createEventLoopGroup(serverWorkerThreadPoolSize, "router-server-worker-thread-%d");
    return new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, serverConnectionBacklog).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            channelGroup.add(ch);
            ChannelPipeline pipeline = ch.pipeline();
            if (isSSLEnabled()) {
                pipeline.addLast("ssl", sslHandlerFactory.create(ch.alloc()));
            }
            pipeline.addLast("http-codec", new HttpServerCodec());
            pipeline.addLast("http-status-request-handler", new HttpStatusRequestHandler());
            if (securityEnabled) {
                pipeline.addLast("access-token-authenticator", new AuthenticationHandler(cConf, tokenValidator, discoveryServiceClient, accessTokenTransformer));
            }
            if (cConf.getBoolean(Constants.Router.ROUTER_AUDIT_LOG_ENABLED)) {
                pipeline.addLast("audit-log", new AuditLogHandler());
            }
            // Always let the client to continue sending the request body after the authentication passed
            pipeline.addLast("expect-continue", new HttpServerExpectContinueHandler());
            // for now there's only one hardcoded rule, but if there will be more, we may want it generic and configurable
            pipeline.addLast("http-request-handler", new HttpRequestRouter(cConf, serviceLookup));
        }
    });
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) HttpServerExpectContinueHandler(io.netty.handler.codec.http.HttpServerExpectContinueHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) BindException(java.net.BindException) ServiceBindException(co.cask.cdap.common.ServiceBindException) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpRequestRouter(co.cask.cdap.gateway.router.handlers.HttpRequestRouter) HttpStatusRequestHandler(co.cask.cdap.gateway.router.handlers.HttpStatusRequestHandler) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) AuditLogHandler(co.cask.cdap.gateway.router.handlers.AuditLogHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) AuthenticationHandler(co.cask.cdap.gateway.router.handlers.AuthenticationHandler)

Example 2 with HttpServerExpectContinueHandler

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

the class HttpHelloWorldServerInitializer method initChannel.

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

Example 3 with HttpServerExpectContinueHandler

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

the class HttpNativeServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    p.addLast(new HttpServerCodec());
    p.addLast(new HttpServerExpectContinueHandler());
    p.addLast(new HttpNativeServerHandler());
}
Also used : HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) HttpServerExpectContinueHandler(io.netty.handler.codec.http.HttpServerExpectContinueHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 4 with HttpServerExpectContinueHandler

use of io.netty.handler.codec.http.HttpServerExpectContinueHandler in project blade by biezhi.

the class HttpServerInitializer method initChannel.

@Override
protected void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    try {
        if (sslCtx != null) {
            pipeline.addLast(sslCtx.newHandler(ch.alloc()));
        }
        pipeline.addLast(new HttpServerCodec());
        pipeline.addLast(new HttpServerExpectContinueHandler());
        if (useGZIP) {
            pipeline.addLast(new HttpContentCompressor());
        }
        if (isWebSocket) {
            pipeline.addLast(new WebSocketHandler(blade));
        }
        pipeline.addLast(new MergeRequestHandler());
        pipeline.addLast(httpServerHandler);
    } catch (Exception e) {
        log.error("Add channel pipeline error", e);
    }
}
Also used : HttpContentCompressor(io.netty.handler.codec.http.HttpContentCompressor) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) HttpServerExpectContinueHandler(io.netty.handler.codec.http.HttpServerExpectContinueHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)4 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)4 HttpServerExpectContinueHandler (io.netty.handler.codec.http.HttpServerExpectContinueHandler)4 ServiceBindException (co.cask.cdap.common.ServiceBindException)1 AuditLogHandler (co.cask.cdap.gateway.router.handlers.AuditLogHandler)1 AuthenticationHandler (co.cask.cdap.gateway.router.handlers.AuthenticationHandler)1 HttpRequestRouter (co.cask.cdap.gateway.router.handlers.HttpRequestRouter)1 HttpStatusRequestHandler (co.cask.cdap.gateway.router.handlers.HttpStatusRequestHandler)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)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 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)1 BindException (java.net.BindException)1