Search in sources :

Example 11 with HttpRequestDecoder

use of io.netty.handler.codec.http.HttpRequestDecoder in project asterixdb by apache.

the class HttpServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    p.addLast(new HttpRequestDecoder(MAX_REQUEST_INITIAL_LINE_LENGTH, MAX_REQUEST_HEADER_SIZE, MAX_REQUEST_CHUNK_SIZE));
    p.addLast(new HttpResponseEncoder());
    p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
    p.addLast(server.createHttpHandler(RESPONSE_CHUNK_SIZE));
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 12 with HttpRequestDecoder

use of io.netty.handler.codec.http.HttpRequestDecoder 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 13 with HttpRequestDecoder

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

the class HttpServer method start.

public ChannelFuture start() throws Exception {
    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.SO_BACKLOG, 1024);
    b.group(group).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast(new HttpRequestDecoder(), new HttpResponseEncoder(), new HttpObjectAggregator(MAX_CONTENT_LENGTH), new Http1RequestHandler());
        }
    });
    Channel ch = b.bind(PORT).sync().channel();
    return ch.closeFuture();
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) LoggingHandler(io.netty.handler.logging.LoggingHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) SocketChannel(io.netty.channel.socket.SocketChannel) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 14 with HttpRequestDecoder

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

the class WebSocketServerHandshaker13Test method testPerformOpeningHandshake0.

private static void testPerformOpeningHandshake0(boolean subProtocol) {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpObjectAggregator(42), new HttpRequestDecoder(), new HttpResponseEncoder());
    FullHttpRequest req = new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat");
    req.headers().set(HttpHeaderNames.HOST, "server.example.com");
    req.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
    req.headers().set(HttpHeaderNames.CONNECTION, "Upgrade");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_KEY, "dGhlIHNhbXBsZSBub25jZQ==");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, "http://example.com");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, "13");
    if (subProtocol) {
        new WebSocketServerHandshaker13("ws://example.com/chat", "chat", false, Integer.MAX_VALUE, false).handshake(ch, req);
    } else {
        new WebSocketServerHandshaker13("ws://example.com/chat", null, false, Integer.MAX_VALUE, false).handshake(ch, req);
    }
    ByteBuf resBuf = ch.readOutbound();
    EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder());
    ch2.writeInbound(resBuf);
    HttpResponse res = ch2.readInbound();
    Assert.assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT));
    if (subProtocol) {
        Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
    } else {
        Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
    }
    ReferenceCountUtil.release(res);
    req.release();
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpResponseDecoder(io.netty.handler.codec.http.HttpResponseDecoder) ByteBuf(io.netty.buffer.ByteBuf)

Example 15 with HttpRequestDecoder

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

the class WebSocketServerHandshaker08Test method testPerformOpeningHandshake0.

private static void testPerformOpeningHandshake0(boolean subProtocol) {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpObjectAggregator(42), new HttpRequestDecoder(), new HttpResponseEncoder());
    FullHttpRequest req = new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat");
    req.headers().set(HttpHeaderNames.HOST, "server.example.com");
    req.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
    req.headers().set(HttpHeaderNames.CONNECTION, "Upgrade");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_KEY, "dGhlIHNhbXBsZSBub25jZQ==");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, "http://example.com");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, "8");
    if (subProtocol) {
        new WebSocketServerHandshaker08("ws://example.com/chat", "chat", false, Integer.MAX_VALUE, false).handshake(ch, req);
    } else {
        new WebSocketServerHandshaker08("ws://example.com/chat", null, false, Integer.MAX_VALUE, false).handshake(ch, req);
    }
    ByteBuf resBuf = ch.readOutbound();
    EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder());
    ch2.writeInbound(resBuf);
    HttpResponse res = ch2.readInbound();
    Assert.assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT));
    if (subProtocol) {
        Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
    } else {
        Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
    }
    ReferenceCountUtil.release(res);
    req.release();
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpResponseDecoder(io.netty.handler.codec.http.HttpResponseDecoder) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)23 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)19 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)12 ChannelPipeline (io.netty.channel.ChannelPipeline)11 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)6 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)5 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)5 SocketChannel (io.netty.channel.socket.SocketChannel)4 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)4 LoggingHandler (io.netty.handler.logging.LoggingHandler)4 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)3 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)3 HttpResponse (io.netty.handler.codec.http.HttpResponse)3 HttpResponseDecoder (io.netty.handler.codec.http.HttpResponseDecoder)3 RequestStateCleanerHandler (com.nike.riposte.server.handler.RequestStateCleanerHandler)2 ByteBuf (io.netty.buffer.ByteBuf)2 Channel (io.netty.channel.Channel)2 ChannelHandler (io.netty.channel.ChannelHandler)2