Package org.playframework.netty.http
Class HttpStreamsServerHandler
- 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.HttpRequest,io.netty.handler.codec.http.HttpResponse>
-
- org.playframework.netty.http.HttpStreamsServerHandler
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
public class HttpStreamsServerHandler extends HttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
Handler that readsHttpRequest
messages followed byHttpContent
messages and producesStreamedHttpRequest
messages, and converts writtenStreamedHttpResponse
messages intoHttpResponse
messages followed byHttpContent
messages. This allows request and response bodies to be handled using reactive streams. There are two types of messages that this handler will send down the chain,StreamedHttpRequest
, andFullHttpRequest
. IfChannelOption.AUTO_READ
is false for the channel, then anyStreamedHttpRequest
messages must be subscribed to consume the body, otherwise it's possible that no read will be done of the messages. There are three types of messages that this handler accepts for writing,StreamedHttpResponse
,WebSocketHttpResponse
andFullHttpResponse
. Writing any other messages may potentially lead to HTTP message mangling. 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 org.playframework.netty.http.HttpStreamsHandler
HttpStreamsHandler.Outgoing
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
close
private boolean
continueExpected
private java.util.List<io.netty.channel.ChannelHandler>
dependentHandlers
private int
inFlight
private io.netty.handler.codec.http.HttpRequest
lastRequest
private boolean
sendContinue
private HttpStreamsHandler.Outgoing
webSocketResponse
-
Constructor Summary
Constructors Constructor Description HttpStreamsServerHandler()
HttpStreamsServerHandler(java.util.List<io.netty.channel.ChannelHandler> dependentHandlers)
Create a new handler that is depended on by the given handlers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
bodyRequested(io.netty.channel.ChannelHandlerContext ctx)
Invoked every time a read of the incoming body is requested by the subscriber.private boolean
canHaveBody(io.netty.handler.codec.http.HttpResponse message)
void
channelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg)
protected void
consumedInMessage(io.netty.channel.ChannelHandlerContext ctx)
Invoked when an incoming message is fully consumed.protected io.netty.handler.codec.http.HttpRequest
createEmptyMessage(io.netty.handler.codec.http.HttpRequest request)
Create an empty incoming message.protected io.netty.handler.codec.http.HttpRequest
createStreamedMessage(io.netty.handler.codec.http.HttpRequest httpRequest, org.reactivestreams.Publisher<io.netty.handler.codec.http.HttpContent> stream)
Create a streamed incoming message with the given stream.void
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
private void
handleWebSocketResponse(io.netty.channel.ChannelHandlerContext ctx, HttpStreamsHandler.Outgoing out)
protected boolean
hasBody(io.netty.handler.codec.http.HttpRequest request)
Whether the given incoming message has a body.protected void
receivedInMessage(io.netty.channel.ChannelHandlerContext ctx)
Invoked when an incoming message is first received.protected void
sentOutMessage(io.netty.channel.ChannelHandlerContext ctx)
Invoked when an outgoing message is fully sent.protected void
unbufferedWrite(io.netty.channel.ChannelHandlerContext ctx, HttpStreamsHandler.Outgoing out)
-
Methods inherited from class org.playframework.netty.http.HttpStreamsHandler
channelReadComplete, receivedOutMessage, subscribeSubscriberToStream, write
-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharable
-
-
-
-
Field Detail
-
lastRequest
private io.netty.handler.codec.http.HttpRequest lastRequest
-
webSocketResponse
private HttpStreamsHandler.Outgoing webSocketResponse
-
inFlight
private int inFlight
-
continueExpected
private boolean continueExpected
-
sendContinue
private boolean sendContinue
-
close
private boolean close
-
dependentHandlers
private final java.util.List<io.netty.channel.ChannelHandler> dependentHandlers
-
-
Constructor Detail
-
HttpStreamsServerHandler
public HttpStreamsServerHandler()
-
HttpStreamsServerHandler
public HttpStreamsServerHandler(java.util.List<io.netty.channel.ChannelHandler> dependentHandlers)
Create a new handler that is depended on by the given handlers. The list of dependent handlers will be removed from the chain when this handler is removed from the chain, for example, when the connection is upgraded to use websockets. This is useful, for example, for removing the reactive streams publisher/subscriber from the chain in that event.- Parameters:
dependentHandlers
- The handlers that depend on this handler.
-
-
Method Detail
-
hasBody
protected boolean hasBody(io.netty.handler.codec.http.HttpRequest request)
Description copied from class:HttpStreamsHandler
Whether the given incoming message has a body.- Specified by:
hasBody
in classHttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
-
createEmptyMessage
protected io.netty.handler.codec.http.HttpRequest createEmptyMessage(io.netty.handler.codec.http.HttpRequest request)
Description copied from class:HttpStreamsHandler
Create 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:
createEmptyMessage
in classHttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
-
createStreamedMessage
protected io.netty.handler.codec.http.HttpRequest createStreamedMessage(io.netty.handler.codec.http.HttpRequest httpRequest, org.reactivestreams.Publisher<io.netty.handler.codec.http.HttpContent> stream)
Description copied from class:HttpStreamsHandler
Create a streamed incoming message with the given stream.- Specified by:
createStreamedMessage
in classHttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
- Specified by:
channelRead
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelRead
in classHttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
- Throws:
java.lang.Exception
-
receivedInMessage
protected void receivedInMessage(io.netty.channel.ChannelHandlerContext ctx)
Description copied from class:HttpStreamsHandler
Invoked when an incoming message is first received. Overridden by sub classes for state tracking.- Overrides:
receivedInMessage
in classHttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
-
sentOutMessage
protected void sentOutMessage(io.netty.channel.ChannelHandlerContext ctx)
Description copied from class:HttpStreamsHandler
Invoked when an outgoing message is fully sent. Overridden by sub classes for state tracking.- Overrides:
sentOutMessage
in classHttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
-
unbufferedWrite
protected void unbufferedWrite(io.netty.channel.ChannelHandlerContext ctx, HttpStreamsHandler.Outgoing out)
- Overrides:
unbufferedWrite
in classHttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
-
canHaveBody
private boolean canHaveBody(io.netty.handler.codec.http.HttpResponse message)
-
consumedInMessage
protected void consumedInMessage(io.netty.channel.ChannelHandlerContext ctx)
Description copied from class:HttpStreamsHandler
Invoked when an incoming message is fully consumed. Overridden by sub classes for state tracking.- Overrides:
consumedInMessage
in classHttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
-
handleWebSocketResponse
private void handleWebSocketResponse(io.netty.channel.ChannelHandlerContext ctx, HttpStreamsHandler.Outgoing out)
-
bodyRequested
protected void bodyRequested(io.netty.channel.ChannelHandlerContext ctx)
Description copied from class:HttpStreamsHandler
Invoked every time a read of the incoming body is requested by the subscriber. Provided so that the server subclass can intercept this to send a 100 continue response.- Overrides:
bodyRequested
in classHttpStreamsHandler<io.netty.handler.codec.http.HttpRequest,io.netty.handler.codec.http.HttpResponse>
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
handlerRemoved
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerRemoved
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
java.lang.Exception
-
-