Class HttpStreamsClientHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
org.playframework.netty.http.HttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>
org.playframework.netty.http.HttpStreamsClientHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler
public class HttpStreamsClientHandler
extends HttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>
Handler that converts written
StreamedHttpRequest messages into HttpRequest messages
followed by HttpContent messages and reads HttpResponse messages followed by
HttpContent messages and produces StreamedHttpResponse messages.
This allows request and response bodies to be handled using reactive streams.
There are two types of messages that this handler accepts for writing, StreamedHttpRequest and
FullHttpRequest. Writing any other messages may potentially lead to HTTP message mangling.
There are two types of messages that this handler will send down the chain, StreamedHttpResponse,
and FullHttpResponse. If ChannelOption.AUTO_READ is false for the channel,
then any StreamedHttpResponse messages must be subscribed to consume the body, otherwise
it's possible that no read will be done of the messages.
As long as messages are returned in the order that they arrive, this handler implicitly supports HTTP
pipelining.-
Nested Class Summary
Nested classes/interfaces inherited from class HttpStreamsHandler
HttpStreamsHandler.OutgoingNested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.reactivestreams.Subscriber<io.netty.handler.codec.http.HttpContent> private StreamedHttpMessageprivate io.netty.channel.ChannelPromiseprivate booleanprivate intprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise future) protected voidconsumedInMessage(io.netty.channel.ChannelHandlerContext ctx) Invoked when an incoming message is fully consumed.protected io.netty.handler.codec.http.HttpResponsecreateEmptyMessage(io.netty.handler.codec.http.HttpResponse response) Create an empty incoming message.protected io.netty.handler.codec.http.HttpResponsecreateStreamedMessage(io.netty.handler.codec.http.HttpResponse response, org.reactivestreams.Publisher<io.netty.handler.codec.http.HttpContent> stream) Create a streamed incoming message with the given stream.protected booleanhasBody(io.netty.handler.codec.http.HttpResponse response) Whether the given incoming message has a body.protected voidreceivedOutMessage(io.netty.channel.ChannelHandlerContext ctx) Invoked when an outgoing message is first received.protected voidsentOutMessage(io.netty.channel.ChannelHandlerContext ctx) Invoked when an outgoing message is fully sent.protected voidsubscribeSubscriberToStream(StreamedHttpMessage msg, org.reactivestreams.Subscriber<io.netty.handler.codec.http.HttpContent> subscriber) Subscribe the given subscriber to the given streamed message.Methods inherited from class HttpStreamsHandler
bodyRequested, channelReadComplete, receivedInMessage, unbufferedWrite, writeMethods inherited from class io.netty.channel.ChannelDuplexHandler
bind, connect, deregister, disconnect, flush, readMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
inFlight
private int inFlight -
withServer
private int withServer -
closeOnZeroInFlight
private io.netty.channel.ChannelPromise closeOnZeroInFlight -
awaiting100Continue
private org.reactivestreams.Subscriber<io.netty.handler.codec.http.HttpContent> awaiting100Continue -
awaiting100ContinueMessage
-
ignoreResponseBody
private boolean ignoreResponseBody
-
-
Constructor Details
-
HttpStreamsClientHandler
public HttpStreamsClientHandler()
-
-
Method Details
-
hasBody
protected boolean hasBody(io.netty.handler.codec.http.HttpResponse response) Description copied from class:HttpStreamsHandlerWhether the given incoming message has a body.- Specified by:
hasBodyin classHttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>
-
close
-
consumedInMessage
protected void consumedInMessage(io.netty.channel.ChannelHandlerContext ctx) Description copied from class:HttpStreamsHandlerInvoked when an incoming message is fully consumed. Overridden by sub classes for state tracking.- Overrides:
consumedInMessagein classHttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>
-
receivedOutMessage
protected void receivedOutMessage(io.netty.channel.ChannelHandlerContext ctx) Description copied from class:HttpStreamsHandlerInvoked when an outgoing message is first received. Overridden by sub classes for state tracking.- Overrides:
receivedOutMessagein classHttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>
-
sentOutMessage
protected void sentOutMessage(io.netty.channel.ChannelHandlerContext ctx) Description copied from class:HttpStreamsHandlerInvoked when an outgoing message is fully sent. Overridden by sub classes for state tracking.- Overrides:
sentOutMessagein classHttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>
-
createEmptyMessage
protected io.netty.handler.codec.http.HttpResponse createEmptyMessage(io.netty.handler.codec.http.HttpResponse response) Description copied from class:HttpStreamsHandlerCreate an empty incoming message. This must be of type FullHttpMessage, and is invoked when we've determined that an incoming message can't have a body, so we send it on as a FullHttpMessage.- Specified by:
createEmptyMessagein classHttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>
-
createStreamedMessage
protected io.netty.handler.codec.http.HttpResponse createStreamedMessage(io.netty.handler.codec.http.HttpResponse response, org.reactivestreams.Publisher<io.netty.handler.codec.http.HttpContent> stream) Description copied from class:HttpStreamsHandlerCreate a streamed incoming message with the given stream.- Specified by:
createStreamedMessagein classHttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>
-
subscribeSubscriberToStream
protected void subscribeSubscriberToStream(StreamedHttpMessage msg, org.reactivestreams.Subscriber<io.netty.handler.codec.http.HttpContent> subscriber) Description copied from class:HttpStreamsHandlerSubscribe the given subscriber to the given streamed message. Provided so that the client subclass can intercept this to hold off sending the body of an expect 100 continue request.- Overrides:
subscribeSubscriberToStreamin classHttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>
-
channelRead
- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classHttpStreamsHandler<io.netty.handler.codec.http.HttpResponse, io.netty.handler.codec.http.HttpRequest>- Throws:
Exception
-