public FullHttpResponse createNettyResponse()

in impl/src/main/java/org/apache/peeco/impl/PeecoChannelHandler.java [130:158]


    public FullHttpResponse createNettyResponse(ChannelHandlerContext ctx, Response response, HttpRequest nettyRequest) throws IOException
    {

        ByteBuf nettyBuffer = ctx.alloc().buffer(response.output().available());

        try
        {
            nettyBuffer.writeBytes(response.output(), response.output().available());
        }
        catch (IOException ex)
        {
            throw new IOException("Response output from HttpHandler could not be written to Netty ByteBuffer.");
        }

        FullHttpResponse nettyResponse = new DefaultFullHttpResponse(
                nettyRequest.protocolVersion(),
                HttpResponseStatus.OK,
                nettyBuffer);

        for (Map.Entry<String, List<String>> headers : response.headers().entrySet())
        {
            nettyResponse.headers().add(headers.getKey(), headers.getValue());
        }

        nettyResponse.headers()
                .setInt(HttpHeaderNames.CONTENT_LENGTH, nettyResponse.content().readableBytes());

        return nettyResponse;
    }