Example usage for io.netty.handler.codec.http LastHttpContent content

List of usage examples for io.netty.handler.codec.http LastHttpContent content

Introduction

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

Prototype

ByteBuf content();

Source Link

Document

Return the data which is held by this ByteBufHolder .

Usage

From source file:io.advantageous.conekt.http.impl.AssembledFullHttpResponse.java

License:Open Source License

public AssembledFullHttpResponse(HttpResponse response, LastHttpContent content) {
    this(response, content.content(), content.trailingHeaders(), content.getDecoderResult());
}

From source file:io.jsync.http.impl.AssembledFullHttpResponse.java

License:Open Source License

public AssembledFullHttpResponse(HttpResponse response, LastHttpContent content) {
    this(response, content.content(), content.trailingHeaders(), content.decoderResult());
}

From source file:io.reactivex.netty.protocol.http.sse.SseChannelHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof HttpResponse) {

        /**/*from w ww . ja v  a 2s.  c o  m*/
         * Since SSE is an endless stream, we can never reuse a connection and hence as soon as SSE traffic is
         * received, the connection is marked as discardable on close.
         */
        ctx.channel().attr(ClientRequestResponseConverter.DISCARD_CONNECTION).set(true); // SSE traffic should always discard connection on close.

        ChannelPipeline pipeline = ctx.channel().pipeline();
        if (!HttpHeaders.isTransferEncodingChunked((HttpResponse) msg)) {
            pipeline.addFirst(SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder());
            /*
             * If there are buffered messages in the previous handler at the time this message is read, we would
             * not be able to convert the content into an SseEvent. For this reason, we also add the decoder after
             * this handler, so that we can handle the buffered messages.
             * See the class level javadoc for more details.
             */
            pipeline.addAfter(NAME, SSE_DECODER_POST_INBOUND_HANDLER, new ServerSentEventDecoder());
        } else {
            pipeline.addAfter(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder());
        }
        ctx.fireChannelRead(msg);
    } else if (msg instanceof LastHttpContent) {
        LastHttpContent lastHttpContent = (LastHttpContent) msg;

        /**
         * The entire pipeline is set based on the assumption that LastHttpContent signals the end of the stream.
         * Since, here we are only passing the content to the rest of the pipeline, it becomes imperative to
         * also pass LastHttpContent as such.
         * For this reason, we send the LastHttpContent again in the pipeline. For this event sent, the content
         * buffer will already be read and hence will not be read again. This message serves as only containing
         * the trailing headers.
         * However, we need to increment the ref count of the content so that the assumptions down the line of the
         * ByteBuf always being released by the last pipeline handler will not break (as ServerSentEventDecoder releases
         * the ByteBuf after read).
         */
        lastHttpContent.content().retain(); // pseudo retain so that the last handler of the pipeline can release it.

        if (lastHttpContent.content().isReadable()) {
            ctx.fireChannelRead(lastHttpContent.content());
        }

        ctx.fireChannelRead(msg); // Since the content is already consumed above (by the SSEDecoder), this is just
        // as sending just trailing headers. This is critical to mark the end of stream.

    } else if (msg instanceof HttpContent) {
        ctx.fireChannelRead(((HttpContent) msg).content());
    } else {
        ctx.fireChannelRead(msg);
    }
}

From source file:io.reactivex.netty.protocol.http.sse.SSEInboundHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof HttpResponse) {
        ChannelPipeline pipeline = ctx.channel().pipeline();
        if (!HttpHeaders.isTransferEncodingChunked((HttpResponse) msg)) {
            pipeline.addFirst(SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder());
            /*/*w ww.  j  a  v a  2 s.c  o  m*/
             * If there are buffered messages in the previous handler at the time this message is read, we would
             * not be able to convert the content into an SseEvent. For this reason, we also add the decoder after
             * this handler, so that we can handle the buffered messages.
             * See the class level javadoc for more details.
             */
            pipeline.addAfter(NAME, SSE_DECODER_POST_INBOUND_HANDLER, new ServerSentEventDecoder());
        } else {
            pipeline.addAfter(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder());
        }
        ctx.fireChannelRead(msg);
    } else if (msg instanceof LastHttpContent) {
        LastHttpContent lastHttpContent = (LastHttpContent) msg;

        /**
         * The entire pipeline is set based on the assumption that LastHttpContent signals the end of the stream.
         * Since, here we are only passing the content to the rest of the pipeline, it becomes imperative to
         * also pass LastHttpContent as such.
         * For this reason, we send the LastHttpContent again in the pipeline. For this event sent, the content
         * buffer will already be read and hence will not be read again. This message serves as only containing
         * the trailing headers.
         * However, we need to increment the ref count of the content so that the assumptions down the line of the
         * ByteBuf always being released by the last pipeline handler will not break (as ServerSentEventDecoder releases
         * the ByteBuf after read).
         */
        lastHttpContent.content().retain(); // pseudo retain so that the last handler of the pipeline can release it.

        if (lastHttpContent.content().isReadable()) {
            ctx.fireChannelRead(lastHttpContent.content());
        }

        ctx.fireChannelRead(msg); // Since the content is already consumed above (by the SSEDecoder), this is just
                                  // as sending just trailing headers. This is critical to mark the end of stream.

    } else if (msg instanceof HttpContent) {
        ctx.fireChannelRead(((HttpContent) msg).content());
    } else {
        ctx.fireChannelRead(msg);
    }
}

From source file:org.vertx.java.core.http.impl.AssembledFullHttpResponse.java

License:Open Source License

public AssembledFullHttpResponse(HttpResponse response, LastHttpContent content) {
    this(response, content.content(), content.trailingHeaders());
}