- java.lang.Object
-
- io.netty5.handler.codec.http2.Http2EventAdapter
-
- io.netty5.handler.codec.http2.InboundHttp2ToHttpAdapter
-
- All Implemented Interfaces:
Http2Connection.Listener,Http2FrameListener
@UnstableApi public class InboundHttp2ToHttpAdapter extends Http2EventAdapter
This adapter provides just header/data events from the HTTP message flow defined in [RFC 7540], Section 8.1.See
HttpToHttp2ConnectionHandlerto get translation from HTTP/1.x objects to HTTP/2 frames for writes.
-
-
Field Summary
Fields Modifier and Type Field Description protected Http2Connectionconnectionprotected booleanvalidateHttpHeaders
-
Constructor Summary
Constructors Modifier Constructor Description protectedInboundHttp2ToHttpAdapter(Http2Connection connection, int maxContentLength, boolean validateHttpHeaders, boolean propagateSettings)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfireChannelRead(ChannelHandlerContext ctx, FullHttpMessage<?> msg, boolean release, Http2Stream stream)Set final headers and fire a channel read eventprotected FullHttpMessage<?>getMessage(Http2Stream stream)Get theFullHttpMessageassociated withstream.protected FullHttpMessage<?>newMessage(Http2Stream stream, Http2Headers headers, boolean validateHttpHeaders, BufferAllocator alloc)Create a newFullHttpMessagebased upon the current connection parametersintonDataRead(ChannelHandlerContext ctx, int streamId, Buffer data, int padding, boolean endOfStream)Handles an inboundDATAframe.voidonHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endOfStream)Handles an inboundHEADERSframe.voidonHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream)Handles an inboundHEADERSframe with priority information specified.voidonPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding)Handles an inboundPUSH_PROMISEframe.voidonRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode)Handles an inboundRST_STREAMframe.protected voidonRstStreamRead(Http2Stream stream, FullHttpMessage<?> msg)Called if aRST_STREAMis received but we have some data for that stream.voidonSettingsRead(ChannelHandlerContext ctx, Http2Settings settings)Handles an inboundSETTINGSframe.voidonStreamRemoved(Http2Stream stream)Notifies the listener that the given stream has now been removed from the connection and will no longer be returned viaHttp2Connection.stream(int).protected FullHttpMessage<?>processHeadersBegin(ChannelHandlerContext ctx, Http2Stream stream, Http2Headers headers, boolean endOfStream, 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(Http2Stream stream, FullHttpMessage<?> message)Makemessagebe the state associated withstream.protected voidremoveMessage(Http2Stream stream, boolean release)The stream is out of scope for the HTTP message flow and will no longer be tracked-
Methods inherited from class io.netty5.handler.codec.http2.Http2EventAdapter
onGoAwayRead, onGoAwayReceived, onGoAwaySent, onPingAckRead, onPingRead, onPriorityRead, onSettingsAckRead, onStreamActive, onStreamAdded, onStreamClosed, onStreamHalfClosed, onUnknownFrame, onWindowUpdateRead
-
-
-
-
Field Detail
-
connection
protected final Http2Connection connection
-
validateHttpHeaders
protected final boolean validateHttpHeaders
-
-
Constructor Detail
-
InboundHttp2ToHttpAdapter
protected InboundHttp2ToHttpAdapter(Http2Connection connection, int maxContentLength, boolean validateHttpHeaders, boolean propagateSettings)
-
-
Method Detail
-
removeMessage
protected final void removeMessage(Http2Stream stream, boolean release)
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 withrelease-trueto call release on the value if it is present.falseto not call release.
-
getMessage
protected final FullHttpMessage<?> getMessage(Http2Stream stream)
Get theFullHttpMessageassociated withstream.- Parameters:
stream- The stream to get the associated state from- Returns:
- The
FullHttpMessageassociated withstream.
-
putMessage
protected final void putMessage(Http2Stream stream, FullHttpMessage<?> 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(Http2Stream stream)
Description copied from interface:Http2Connection.ListenerNotifies the listener that the given stream has now been removed from the connection and will no longer be returned viaHttp2Connection.stream(int). The connection may maintain inactive streams for some time before removing them.If a
RuntimeExceptionis thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.- Specified by:
onStreamRemovedin interfaceHttp2Connection.Listener- Overrides:
onStreamRemovedin classHttp2EventAdapter
-
fireChannelRead
protected void fireChannelRead(ChannelHandlerContext ctx, FullHttpMessage<?> msg, boolean release, Http2Stream stream)
Set final headers and fire a channel read event- Parameters:
ctx- The context to fire the event onmsg- The message to sendrelease-trueto call release on the value if it is present.falseto not call release.stream- the stream of the message which is being fired
-
newMessage
protected FullHttpMessage<?> newMessage(Http2Stream stream, Http2Headers headers, boolean validateHttpHeaders, BufferAllocator alloc) throws Http2Exception
Create a newFullHttpMessagebased upon the current connection parameters- Parameters:
stream- 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
alloc- TheBufferAllocatorto use to generate the content of the message- Throws:
Http2Exception- If there is an error when creatingFullHttpMessagefromHttp2StreamandHttp2Headers
-
processHeadersBegin
protected FullHttpMessage<?> processHeadersBegin(ChannelHandlerContext ctx, Http2Stream stream, Http2Headers headers, boolean endOfStream, boolean allowAppend, boolean appendToTrailer) throws Http2Exception
Provides 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 processendOfStream-trueif thestreamhas received the end of stream flagallowAppend-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:
Http2Exception- If the stream id is not in the correct state to process the headers request
-
onDataRead
public int onDataRead(ChannelHandlerContext ctx, int streamId, Buffer data, int padding, boolean endOfStream) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundDATAframe.- Specified by:
onDataReadin interfaceHttp2FrameListener- Overrides:
onDataReadin classHttp2EventAdapter- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.data- payload buffer for the frame. This buffer will be released by the codec.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).endOfStream- Indicates whether this is the last frame to be sent from the remote endpoint for this stream.- Returns:
- the number of bytes that have been processed by the application. The returned bytes are used by the
inbound flow controller to determine the appropriate time to expand the inbound flow control window (i.e. send
WINDOW_UPDATE). Returning a value equal to the length ofdata+paddingwill effectively opt-out of application-level flow control for this frame. Returning a value less than the length ofdata+paddingwill defer the returning of the processed bytes, which the application must later return viaHttp2LocalFlowController.consumeBytes(Http2Stream, int). The returned value must be >=0and <=data.readableBytes()+padding. - Throws:
Http2Exception
-
onHeadersRead
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endOfStream) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundHEADERSframe.Only one of the following methods will be called for each
HEADERSframe sequence. One will be called when theEND_HEADERSflag has been received.Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, boolean)Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, short, boolean, int, boolean)Http2FrameListener.onPushPromiseRead(ChannelHandlerContext, int, int, Http2Headers, int)
To say it another way; the
Http2Headerswill contain all of the headers for the current message exchange step (additional queuing is not necessary).- Specified by:
onHeadersReadin interfaceHttp2FrameListener- Overrides:
onHeadersReadin classHttp2EventAdapter- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.headers- the received headers.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).endOfStream- Indicates whether this is the last frame to be sent from the remote endpoint for this stream.- Throws:
Http2Exception
-
onHeadersRead
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundHEADERSframe with priority information specified. Only called ifEND_HEADERSencountered.Only one of the following methods will be called for each
HEADERSframe sequence. One will be called when theEND_HEADERSflag has been received.Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, boolean)Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, short, boolean, int, boolean)Http2FrameListener.onPushPromiseRead(ChannelHandlerContext, int, int, Http2Headers, int)
To say it another way; the
Http2Headerswill contain all of the headers for the current message exchange step (additional queuing is not necessary).- Specified by:
onHeadersReadin interfaceHttp2FrameListener- Overrides:
onHeadersReadin classHttp2EventAdapter- Parameters:
ctx- the context from the handler where the frame was read.streamId- the subject stream for the frame.headers- the received headers.streamDependency- the stream on which this stream depends, or 0 if dependent on the connection.weight- the new weight for the stream.exclusive- whether or not the stream should be the exclusive dependent of its parent.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).endOfStream- Indicates whether this is the last frame to be sent from the remote endpoint for this stream.- Throws:
Http2Exception
-
onRstStreamRead
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundRST_STREAMframe.- Specified by:
onRstStreamReadin interfaceHttp2FrameListener- Overrides:
onRstStreamReadin classHttp2EventAdapter- Parameters:
ctx- the context from the handler where the frame was read.streamId- the stream that is terminating.errorCode- the error code identifying the type of failure.- Throws:
Http2Exception
-
onPushPromiseRead
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundPUSH_PROMISEframe. Only called ifEND_HEADERSencountered.Promised requests MUST be authoritative, cacheable, and safe. See [RFC 7540], Section 8.2.
Only one of the following methods will be called for each
HEADERSframe sequence. One will be called when theEND_HEADERSflag has been received.Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, boolean)Http2FrameListener.onHeadersRead(ChannelHandlerContext, int, Http2Headers, int, short, boolean, int, boolean)Http2FrameListener.onPushPromiseRead(ChannelHandlerContext, int, int, Http2Headers, int)
To say it another way; the
Http2Headerswill contain all of the headers for the current message exchange step (additional queuing is not necessary).- Specified by:
onPushPromiseReadin interfaceHttp2FrameListener- Overrides:
onPushPromiseReadin classHttp2EventAdapter- Parameters:
ctx- the context from the handler where the frame was read.streamId- the stream the frame was sent on.promisedStreamId- the ID of the promised stream.headers- the received headers.padding- additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).- Throws:
Http2Exception
-
onSettingsRead
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception
Description copied from interface:Http2FrameListenerHandles an inboundSETTINGSframe.- Specified by:
onSettingsReadin interfaceHttp2FrameListener- Overrides:
onSettingsReadin classHttp2EventAdapter- Parameters:
ctx- the context from the handler where the frame was read.settings- the settings received from the remote endpoint.- Throws:
Http2Exception
-
onRstStreamRead
protected void onRstStreamRead(Http2Stream stream, FullHttpMessage<?> msg)
Called if aRST_STREAMis received but we have some data for that stream.
-
-