io.reactivex.netty.protocol.http.sse.SSEInboundHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rx-netty Show documentation
Show all versions of rx-netty Show documentation
rx-netty developed by Netflix
/*
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.reactivex.netty.protocol.http.sse;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
import io.reactivex.netty.protocol.http.client.ClientRequestResponseConverter;
import io.reactivex.netty.protocol.text.sse.ServerSentEventDecoder;
/**
* A handler to insert {@link ServerSentEventDecoder} at a proper position in the pipeline according to the protocol.
* There are the following cases, this handles:
*
* Http response with chunked encoding
* In this case, the {@link ServerSentEventDecoder} is inserted after this {@link SSEInboundHandler}
*
* Http response with no chunking
* In this case, the {@link ServerSentEventDecoder} is inserted as the first handler in the pipeline. This makes the
* {@link ByteBuf} at the origin to be converted to {@link io.reactivex.netty.protocol.text.sse.ServerSentEvent} and hence any other handler will not look at this
* message unless it is really interested.
* Caveat
* In some cases where any message is buffered before this pipeline change is made by this handler (i.e. adding
* {@link ServerSentEventDecoder} as the first handler), the {@link ServerSentEventDecoder} will not be applied to those
* messages. For this reason we also add {@link ServerSentEventDecoder} after this handler. In cases, where the first
* {@link ServerSentEventDecoder} is applied on the incoming data, the next instance of {@link ServerSentEventDecoder}
* will be redundant.
*
* No HTTP protocol
* In this case, the handler does not do anything, assuming that there is no special handling required.
*
*/
@ChannelHandler.Sharable
public class SSEInboundHandler extends SimpleChannelInboundHandler
© 2015 - 2024 Weber Informatics LLC | Privacy Policy