Example usage for io.netty.handler.codec.http FullHttpResponse duplicate

List of usage examples for io.netty.handler.codec.http FullHttpResponse duplicate

Introduction

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

Prototype

@Override
    FullHttpResponse duplicate();

Source Link

Usage

From source file:com.flysoloing.learning.network.netty.http2.tiles.FallbackRequestHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest req) throws Exception {
    if (HttpUtil.is100ContinueExpected(req)) {
        ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
    }//w  ww.j  a  v a 2 s.c  om

    ByteBuf content = ctx.alloc().buffer();
    content.writeBytes(response.duplicate());

    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
    response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
    response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());

    ctx.write(response).addListener(ChannelFutureListener.CLOSE);
}

From source file:io.netty.example.http2.tiles.FallbackRequestHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest req) throws Exception {
    if (HttpUtil.is100ContinueExpected(req)) {
        ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE, EMPTY_BUFFER));
    }//from  w w w.j  av  a2  s.  c  o m

    ByteBuf content = ctx.alloc().buffer();
    content.writeBytes(response.duplicate());

    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
    response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
    response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());

    ctx.write(response).addListener(ChannelFutureListener.CLOSE);
}