
io.reactivex.netty.protocol.http.sse.SseChannelHandler Maven / Gradle / Ivy
/*
* 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.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;
/**
* 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 SseChannelHandler}
*
* Http response with no chunking
* In this case, the {@link ServerSentEventDecoder} is inserted as the first handler in the pipeline. This makes the
* {@link io.netty.buffer.ByteBuf} at the origin to be converted to {@link 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.
*
*/
@ChannelHandler.Sharable
public class SseChannelHandler extends SimpleChannelInboundHandler
© 2015 - 2025 Weber Informatics LLC | Privacy Policy