Package io.micronaut.http.netty.stream
Class StreamingInboundHttp2ToHttpAdapter
- java.lang.Object
-
- io.netty.handler.codec.http2.Http2EventAdapter
-
- io.micronaut.http.netty.stream.StreamingInboundHttp2ToHttpAdapter
-
- All Implemented Interfaces:
io.netty.handler.codec.http2.Http2Connection.Listener,io.netty.handler.codec.http2.Http2FrameListener
public class StreamingInboundHttp2ToHttpAdapter extends io.netty.handler.codec.http2.Http2EventAdapterImplementation ofHttp2EventAdapterthat allows streaming requests for servers and responses for clients by establishing a processor that emits chunks asHttpContent. This implementation does not buffer the data. If you need data buffering aFlowControlHandlercan be placed after this implementation so that downstream handlers can control flow. Based on code inInboundHttp2ToHttpAdapter.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description protected io.netty.handler.codec.http2.Http2Connectionconnectionprotected booleanvalidateHttpHeaders
-
Constructor Summary
Constructors Constructor Description StreamingInboundHttp2ToHttpAdapter(io.netty.handler.codec.http2.Http2Connection connection, int maxContentLength)Default constructor.StreamingInboundHttp2ToHttpAdapter(io.netty.handler.codec.http2.Http2Connection connection, int maxContentLength, boolean validateHttpHeaders, boolean propagateSettings)Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfireChannelRead(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpContent msg, io.netty.handler.codec.http2.Http2Stream stream)fire a channel read event.protected voidfireChannelRead(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpMessage msg, io.netty.handler.codec.http2.Http2Stream stream)fire a channel read event.protected io.netty.handler.codec.http.HttpMessagegetMessage(io.netty.handler.codec.http2.Http2Stream stream)Get theFullHttpMessageassociated withstream.protected io.netty.handler.codec.http.HttpMessagenewMessage(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http2.Http2Headers headers, boolean validateHttpHeaders)Create a newFullHttpMessagebased upon the current connection parameters.intonDataRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.buffer.ByteBuf data, int padding, boolean endOfStream)voidonHeadersRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.handler.codec.http2.Http2Headers headers, int padding, boolean endOfStream)voidonHeadersRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.handler.codec.http2.Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream)voidonPushPromiseRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, int promisedStreamId, io.netty.handler.codec.http2.Http2Headers headers, int padding)voidonRstStreamRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, long errorCode)protected voidonRstStreamRead(io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http.HttpMessage msg)Called if aRST_STREAMis received but we have some data for that stream.voidonSettingsRead(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Settings settings)voidonStreamRemoved(io.netty.handler.codec.http2.Http2Stream stream)protected io.netty.handler.codec.http.HttpMessageprocessHeadersBegin(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http2.Http2Headers headers, boolean allowAppend, boolean appendToTrailer)Provides translation between HTTP/2 and HTTP header objects while ensuring the stream is in a valid state for additional headers.protected voidputMessage(io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http.HttpMessage message)Makemessagebe the state associated withstream.protected voidremoveMessage(io.netty.handler.codec.http2.Http2Stream stream)The stream is out of scope for the HTTP message flow and will no longer be tracked.
-
-
-
Constructor Detail
-
StreamingInboundHttp2ToHttpAdapter
public StreamingInboundHttp2ToHttpAdapter(io.netty.handler.codec.http2.Http2Connection connection, int maxContentLength, boolean validateHttpHeaders, boolean propagateSettings)Default constructor.- Parameters:
connection- The connectionmaxContentLength- The max content lengthvalidateHttpHeaders- Whether to validate headerspropagateSettings- Whether to propagate settings
-
StreamingInboundHttp2ToHttpAdapter
public StreamingInboundHttp2ToHttpAdapter(io.netty.handler.codec.http2.Http2Connection connection, int maxContentLength)Default constructor.- Parameters:
connection- The connectionmaxContentLength- The max content length
-
-
Method Detail
-
removeMessage
protected final void removeMessage(io.netty.handler.codec.http2.Http2Stream stream)
The stream is out of scope for the HTTP message flow and will no longer be tracked.- Parameters:
stream- The stream to remove associated state with
-
getMessage
protected final io.netty.handler.codec.http.HttpMessage getMessage(io.netty.handler.codec.http2.Http2Stream stream)
Get theFullHttpMessageassociated withstream.- Parameters:
stream- The stream to get the associated state from- Returns:
- The
FullHttpMessageassociated withstream.
-
putMessage
protected final void putMessage(io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http.HttpMessage message)Makemessagebe the state associated withstream.- Parameters:
stream- The stream whichmessageis associated with.message- The message which contains the HTTP semantics.
-
onStreamRemoved
public void onStreamRemoved(io.netty.handler.codec.http2.Http2Stream stream)
- Specified by:
onStreamRemovedin interfaceio.netty.handler.codec.http2.Http2Connection.Listener- Overrides:
onStreamRemovedin classio.netty.handler.codec.http2.Http2EventAdapter
-
fireChannelRead
protected void fireChannelRead(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpContent msg, io.netty.handler.codec.http2.Http2Stream stream)fire a channel read event.- Parameters:
ctx- The context to fire the event onmsg- The message to sendstream- the stream of the message which is being fired
-
fireChannelRead
protected void fireChannelRead(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpMessage msg, io.netty.handler.codec.http2.Http2Stream stream)fire a channel read event.- Parameters:
ctx- The context to fire the event onmsg- The message to sendstream- the stream of the message which is being fired
-
newMessage
protected io.netty.handler.codec.http.HttpMessage newMessage(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http2.Http2Headers headers, boolean validateHttpHeaders) throws io.netty.handler.codec.http2.Http2ExceptionCreate a newFullHttpMessagebased upon the current connection parameters.- Parameters:
ctx- The channel contextstream- The stream to create a message forheaders- The headers associated withstreamvalidateHttpHeaders-trueto validate HTTP headers in the http-codecfalsenot to validate HTTP headers in the http-codec
- Returns:
- A new
StreamedHttpMessage - Throws:
io.netty.handler.codec.http2.Http2Exception- thrown if an error occurs creating the request
-
processHeadersBegin
protected io.netty.handler.codec.http.HttpMessage processHeadersBegin(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http2.Http2Headers headers, boolean allowAppend, boolean appendToTrailer) throws io.netty.handler.codec.http2.Http2ExceptionProvides translation between HTTP/2 and HTTP header objects while ensuring the stream is in a valid state for additional headers.- Parameters:
ctx- The context for which this message has been received. Used to send informational header if detected.stream- The stream theheadersapply toheaders- The headers to processallowAppend-trueif headers will be appended if the stream already exists.- if
falseand the stream already exists this method returnsnull.
appendToTrailer-trueif a messagestreamalready exists then the headers should be added to the trailing headers.falsethen appends will be done to the initial headers.
- Returns:
- The object used to track the stream corresponding to
stream.nullifallowAppendisfalseand the stream already exists. - Throws:
io.netty.handler.codec.http2.Http2Exception- If the stream id is not in the correct state to process the headers request
-
onDataRead
public int onDataRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.buffer.ByteBuf data, int padding, boolean endOfStream) throws io.netty.handler.codec.http2.Http2Exception- Specified by:
onDataReadin interfaceio.netty.handler.codec.http2.Http2FrameListener- Overrides:
onDataReadin classio.netty.handler.codec.http2.Http2EventAdapter- Throws:
io.netty.handler.codec.http2.Http2Exception
-
onHeadersRead
public void onHeadersRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.handler.codec.http2.Http2Headers headers, int padding, boolean endOfStream) throws io.netty.handler.codec.http2.Http2Exception- Specified by:
onHeadersReadin interfaceio.netty.handler.codec.http2.Http2FrameListener- Overrides:
onHeadersReadin classio.netty.handler.codec.http2.Http2EventAdapter- Throws:
io.netty.handler.codec.http2.Http2Exception
-
onHeadersRead
public void onHeadersRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.handler.codec.http2.Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream) throws io.netty.handler.codec.http2.Http2Exception- Specified by:
onHeadersReadin interfaceio.netty.handler.codec.http2.Http2FrameListener- Overrides:
onHeadersReadin classio.netty.handler.codec.http2.Http2EventAdapter- Throws:
io.netty.handler.codec.http2.Http2Exception
-
onRstStreamRead
public void onRstStreamRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, long errorCode)- Specified by:
onRstStreamReadin interfaceio.netty.handler.codec.http2.Http2FrameListener- Overrides:
onRstStreamReadin classio.netty.handler.codec.http2.Http2EventAdapter
-
onPushPromiseRead
public void onPushPromiseRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, int promisedStreamId, io.netty.handler.codec.http2.Http2Headers headers, int padding) throws io.netty.handler.codec.http2.Http2Exception- Specified by:
onPushPromiseReadin interfaceio.netty.handler.codec.http2.Http2FrameListener- Overrides:
onPushPromiseReadin classio.netty.handler.codec.http2.Http2EventAdapter- Throws:
io.netty.handler.codec.http2.Http2Exception
-
onSettingsRead
public void onSettingsRead(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Settings settings) throws io.netty.handler.codec.http2.Http2Exception- Specified by:
onSettingsReadin interfaceio.netty.handler.codec.http2.Http2FrameListener- Overrides:
onSettingsReadin classio.netty.handler.codec.http2.Http2EventAdapter- Throws:
io.netty.handler.codec.http2.Http2Exception
-
onRstStreamRead
protected void onRstStreamRead(io.netty.handler.codec.http2.Http2Stream stream, io.netty.handler.codec.http.HttpMessage msg)Called if aRST_STREAMis received but we have some data for that stream.- Parameters:
stream- The streammsg- The message
-
-