@Internal public class HttpStreamsClientHandler extends io.netty.channel.ChannelDuplexHandler
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.
Modifier and Type | Field and Description |
---|---|
static String |
HANDLER_BODY_PUBLISHER |
Constructor and Description |
---|
HttpStreamsClientHandler()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
bodyRequested(io.netty.channel.ChannelHandlerContext ctx)
Invoked every time a read of the incoming body is requested by the subscriber.
|
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
void |
channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) |
void |
close(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise future) |
protected void |
consumedInMessage(io.netty.channel.ChannelHandlerContext ctx)
Invoked when an incoming message is fully consumed.
|
protected io.netty.handler.codec.http.HttpResponse |
createEmptyMessage(io.netty.handler.codec.http.HttpResponse response)
Create an empty incoming message.
|
protected io.netty.handler.codec.http.HttpResponse |
createStreamedMessage(io.netty.handler.codec.http.HttpResponse response,
Publisher<? extends io.netty.handler.codec.http.HttpContent> stream)
Create a streamed incoming message with the given stream.
|
protected int |
getStreamId(Object msg)
Gets the stream ID from the message.
|
protected boolean |
hasBody(io.netty.handler.codec.http.HttpResponse response)
Whether the given incoming message has a body.
|
protected boolean |
isClient() |
protected boolean |
isValidInMessage(Object msg) |
protected boolean |
isValidOutMessage(Object msg) |
protected void |
receivedInMessage(io.netty.channel.ChannelHandlerContext ctx)
Invoked when an incoming message is first received.
|
protected void |
receivedOutMessage(io.netty.channel.ChannelHandlerContext ctx)
Invoked when an outgoing message is first received.
|
protected void |
sentOutMessage(io.netty.channel.ChannelHandlerContext ctx)
Invoked when an outgoing message is fully sent.
|
protected void |
subscribeSubscriberToStream(StreamedHttpMessage msg,
Subscriber<io.netty.handler.codec.http.HttpContent> subscriber)
Subscribe the given subscriber to the given streamed message.
|
protected void |
unbufferedWrite(io.netty.channel.ChannelHandlerContext ctx,
Out message,
io.netty.channel.ChannelPromise promise) |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise) |
bind, connect, deregister, disconnect, flush, read
channelActive, channelInactive, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
public static final String HANDLER_BODY_PUBLISHER
protected boolean hasBody(io.netty.handler.codec.http.HttpResponse response)
response
- The incoming messagepublic void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise future) throws Exception
close
in interface io.netty.channel.ChannelOutboundHandler
close
in class io.netty.channel.ChannelDuplexHandler
Exception
protected void consumedInMessage(io.netty.channel.ChannelHandlerContext ctx)
Overridden by sub classes for state tracking.
ctx
- The channel handler contextprotected void receivedOutMessage(io.netty.channel.ChannelHandlerContext ctx)
Overridden by sub classes for state tracking.
ctx
- The channel handler contextprotected void sentOutMessage(io.netty.channel.ChannelHandlerContext ctx)
Overridden by sub classes for state tracking.
ctx
- The channel handler contextprotected io.netty.handler.codec.http.HttpResponse createEmptyMessage(io.netty.handler.codec.http.HttpResponse response)
response
- The incoming messageprotected io.netty.handler.codec.http.HttpResponse createStreamedMessage(io.netty.handler.codec.http.HttpResponse response, Publisher<? extends io.netty.handler.codec.http.HttpContent> stream)
response
- The incoming messagestream
- The publisher for the Http Contentprotected void subscribeSubscriberToStream(StreamedHttpMessage msg, Subscriber<io.netty.handler.codec.http.HttpContent> subscriber)
Provided so that the client subclass can intercept this to hold off sending the body of an expect 100 continue request.
msg
- The streamed Http messagesubscriber
- The subscriber for the Http Contentprotected final boolean isClient()
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
channelRead
in interface io.netty.channel.ChannelInboundHandler
Exception
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception
write
in interface io.netty.channel.ChannelOutboundHandler
Exception
protected void receivedInMessage(io.netty.channel.ChannelHandlerContext ctx)
Overridden by sub classes for state tracking.
ctx
- The channel handler contextprotected void bodyRequested(io.netty.channel.ChannelHandlerContext ctx)
Provided so that the server subclass can intercept this to send a 100 continue response.
ctx
- The channel handler contextprotected int getStreamId(Object msg)
msg
- The messagepublic void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelReadComplete
in interface io.netty.channel.ChannelInboundHandler
channelReadComplete
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx)
channelWritabilityChanged
in interface io.netty.channel.ChannelInboundHandler
channelWritabilityChanged
in class io.netty.channel.ChannelInboundHandlerAdapter
protected void unbufferedWrite(io.netty.channel.ChannelHandlerContext ctx, Out message, io.netty.channel.ChannelPromise promise)
ctx
- The channel handler contextmessage
- The messagepromise
- The promiseprotected boolean isValidOutMessage(Object msg)
msg
- The messageprotected boolean isValidInMessage(Object msg)
msg
- The message