Search in sources :

Example 16 with HttpServerCodec

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

the class SpdyOrHttpHandler method configureHttp1.

private static void configureHttp1(ChannelHandlerContext ctx) throws Exception {
    ChannelPipeline p = ctx.pipeline();
    p.addLast(new HttpServerCodec());
    p.addLast(new HttpObjectAggregator(MAX_CONTENT_LENGTH));
    p.addLast(new SpdyServerHandler());
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 17 with HttpServerCodec

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

the class Http2ServerInitializer method configureClearText.

/**
     * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.0
     */
private void configureClearText(SocketChannel ch) {
    final ChannelPipeline p = ch.pipeline();
    final HttpServerCodec sourceCodec = new HttpServerCodec();
    p.addLast(sourceCodec);
    p.addLast(new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory));
    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.
            System.err.println("Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)");
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null, new HelloWorldHttp1Handler("Direct. No Upgrade Attempted."));
            pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
            ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
        }
    });
    p.addLast(new UserEventLogger());
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HelloWorldHttp1Handler(io.netty.example.http2.helloworld.server.HelloWorldHttp1Handler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) HttpMessage(io.netty.handler.codec.http.HttpMessage) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 18 with HttpServerCodec

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

the class Http2ServerInitializer method configureClearText.

/**
     * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.0
     */
private void configureClearText(SocketChannel ch) {
    final ChannelPipeline p = ch.pipeline();
    final HttpServerCodec sourceCodec = new HttpServerCodec();
    p.addLast(sourceCodec);
    p.addLast(new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory));
    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.
            System.err.println("Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)");
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null, new HelloWorldHttp1Handler("Direct. No Upgrade Attempted."));
            pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
            ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
        }
    });
    p.addLast(new UserEventLogger());
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) HttpMessage(io.netty.handler.codec.http.HttpMessage) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 19 with HttpServerCodec

use of io.netty.handler.codec.http.HttpServerCodec in project async-http-client by AsyncHttpClient.

the class HttpStaticFileServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    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)

Aggregations

HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)19 ChannelPipeline (io.netty.channel.ChannelPipeline)18 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)13 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 HttpServerUpgradeHandler (io.netty.handler.codec.http.HttpServerUpgradeHandler)4 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)4 HttpMessage (io.netty.handler.codec.http.HttpMessage)3 WebSocketServerProtocolHandler (io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler)2 Http2ServerUpgradeCodec (io.netty.handler.codec.http2.Http2ServerUpgradeCodec)2 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 HelloWorldHttp1Handler (io.netty.example.http2.helloworld.server.HelloWorldHttp1Handler)1