Top Description Inners Fields Constructors Methods
io.netty5.handler.codec.http2

public Class InboundHttp2ToHttpAdapter

extends Http2EventAdapter
Class Inheritance
Annotations
@UnstableApi
Imports
io.netty5.buffer.Buffer, .BufferAllocator, io.netty5.channel.ChannelHandlerContext, io.netty5.handler.codec.http.DefaultFullHttpRequest, .FullHttpMessage, .FullHttpRequest, .FullHttpResponse, .HttpHeaderNames, .HttpStatusClass, .HttpUtil, io.netty5.handler.codec.http2.headers.Http2Headers, io.netty5.util.internal.UnstableApi

This adapter provides just header/data events from the HTTP message flow defined in [RFC 7540], Section 8.1.

See HttpToHttp2ConnectionHandler to get translation from HTTP/1.x objects to HTTP/2 frames for writes.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
InboundHttp2ToHttpAdapter.ImmediateSendDetector

Allows messages to be sent up the pipeline before the next phase in the HTTP message flow is detected.

Field Summary

Modifier and TypeField and Description
protected final Http2Connection
private static final InboundHttp2ToHttpAdapter.ImmediateSendDetector
private final int
private final Http2Connection.PropertyKey
private final boolean
private final InboundHttp2ToHttpAdapter.ImmediateSendDetector
protected final boolean

Constructor Summary

AccessConstructor and Description
protected
InboundHttp2ToHttpAdapter(Http2Connection connection, int maxContentLength, boolean validateHttpHeaders, boolean propagateSettings)

Method Summary

Modifier and TypeMethod and Description
protected void
fireChannelRead(ChannelHandlerContext
The context to fire the event on
ctx
,
FullHttpMessage<?>
The message to send
msg
,
boolean
true to call release on the value if it is present. false to not call release.
release
,
Http2Stream
the stream of the message which is being fired
stream
)

Set final headers and fire a channel read event

protected final FullHttpMessage<?>

Returns:

The FullHttpMessage associated with stream.
getMessage
(Http2Stream
The stream to get the associated state from
stream
)

Get the FullHttpMessage associated with stream.

protected FullHttpMessage<?>
newMessage(Http2Stream
The stream to create a message for
stream
,
Http2Headers
The headers associated with stream
headers
,
boolean
  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
validateHttpHeaders
,
BufferAllocator
The BufferAllocator to use to generate the content of the message
alloc
)

Create a new FullHttpMessage based upon the current connection parameters

public int
onDataRead(ChannelHandlerContext
the context from the handler where the frame was read.
ctx
,
int
the subject stream for the frame.
streamId
,
Buffer
payload buffer for the frame. This buffer will be closed by the codec when the method returns (the buffer will be inaccessible after the method call).
data
,
int
additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
padding
,
boolean
Indicates whether this is the last frame to be sent from the remote endpoint for this stream.
endOfStream
)

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onDataRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onDataRead.

Handles an inbound DATA frame.
public void
onHeadersRead(ChannelHandlerContext
the context from the handler where the frame was read.
ctx
,
int
the subject stream for the frame.
streamId
,
Http2Headers
the received headers.
headers
,
int
additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
padding
,
boolean
Indicates whether this is the last frame to be sent from the remote endpoint for this stream.
endOfStream
)

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onHeadersRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onHeadersRead.

Handles an inbound HEADERS frame.
public void
onHeadersRead(ChannelHandlerContext
the context from the handler where the frame was read.
ctx
,
int
the subject stream for the frame.
streamId
,
Http2Headers
the received headers.
headers
,
int
the stream on which this stream depends, or 0 if dependent on the connection.
streamDependency
,
short
the new weight for the stream.
weight
,
boolean
whether or not the stream should be the exclusive dependent of its parent.
exclusive
,
int
additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
padding
,
boolean
Indicates whether this is the last frame to be sent from the remote endpoint for this stream.
endOfStream
)

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onHeadersRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onHeadersRead.

Handles an inbound HEADERS frame with priority information specified.
public void
onPushPromiseRead(ChannelHandlerContext
the context from the handler where the frame was read.
ctx
,
int
the stream the frame was sent on.
streamId
,
int
the ID of the promised stream.
promisedStreamId
,
Http2Headers
the received headers.
headers
,
int
additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).
padding
)

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onPushPromiseRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onPushPromiseRead.

Handles an inbound PUSH_PROMISE frame.
public void
onRstStreamRead(ChannelHandlerContext
the context from the handler where the frame was read.
ctx
,
int
the stream that is terminating.
streamId
,
long
the error code identifying the type of failure.
errorCode
)

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onRstStreamRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onRstStreamRead.

Handles an inbound RST_STREAM frame.
protected void
onRstStreamRead(Http2Stream stream, FullHttpMessage<?> msg)

Called if a RST_STREAM is received but we have some data for that stream.

public void
onSettingsRead(ChannelHandlerContext
the context from the handler where the frame was read.
ctx
,
Http2Settings
the settings received from the remote endpoint.
settings
)

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onSettingsRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onSettingsRead.

Handles an inbound SETTINGS frame.
public void
onStreamRemoved(Http2Stream stream)

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onStreamRemoved.

Implements io.netty5.handler.codec.http2.Http2Connection.Listener.onStreamRemoved.

Notifies the listener that the given stream has now been removed from the connection and will no longer be returned via Http2Connection#stream(int).
protected FullHttpMessage<?>

Returns:

The object used to track the stream corresponding to stream. null if allowAppend is false and the stream already exists.
processHeadersBegin
(ChannelHandlerContext
The context for which this message has been received. Used to send informational header if detected.
ctx
,
Http2Stream
The stream the headers apply to
stream
,
Http2Headers
The headers to process
headers
,
boolean
true if the stream has received the end of stream flag
endOfStream
,
boolean
  • true if headers will be appended if the stream already exists.
  • if false and the stream already exists this method returns null.
allowAppend
,
boolean
  • true if a message stream already exists then the headers should be added to the trailing headers.
  • false then appends will be done to the initial headers.
appendToTrailer
)

Provides translation between HTTP/2 and HTTP header objects while ensuring the stream is in a valid state for additional headers.

private void
processHeadersEnd(ChannelHandlerContext
The context for which this message has been received
ctx
,
Http2Stream
The stream the objAccumulator corresponds to
stream
,
FullHttpMessage<?>
The object which represents all headers/data for corresponding to stream
msg
,
boolean
true if this is the last event for the stream
endOfStream
)

After HTTP/2 headers have been processed by processHeadersBegin this method either sends the result up the pipeline or retains the message for future processing.

protected final void
putMessage(Http2Stream
The stream which message is associated with.
stream
,
FullHttpMessage<?>
The message which contains the HTTP semantics.
message
)

Make message be the state associated with stream.

protected final void
removeMessage(Http2Stream
The stream to remove associated state with
stream
,
boolean
true to call release on the value if it is present. false to not call release.
release
)

The stream is out of scope for the HTTP message flow and will no longer be tracked

Inherited from io.netty5.handler.codec.http2.Http2EventAdapter:
onGoAwayReadonGoAwayReceivedonGoAwaySentonPingAckReadonPingReadonPriorityReadonSettingsAckReadonStreamActiveonStreamAddedonStreamClosedonStreamHalfClosedonUnknownFrameonWindowUpdateRead

Field Detail

connectionback to summary
protected final Http2Connection connection
DEFAULT_SEND_DETECTORback to summary
private static final InboundHttp2ToHttpAdapter.ImmediateSendDetector DEFAULT_SEND_DETECTOR
maxContentLengthback to summary
private final int maxContentLength
messageKeyback to summary
private final Http2Connection.PropertyKey messageKey
propagateSettingsback to summary
private final boolean propagateSettings
sendDetectorback to summary
private final InboundHttp2ToHttpAdapter.ImmediateSendDetector sendDetector
validateHttpHeadersback to summary
protected final boolean validateHttpHeaders

Constructor Detail

InboundHttp2ToHttpAdapterback to summary
protected InboundHttp2ToHttpAdapter(Http2Connection connection, int maxContentLength, boolean validateHttpHeaders, boolean propagateSettings)

Method Detail

fireChannelReadback to summary
protected void fireChannelRead(ChannelHandlerContext ctx, FullHttpMessage<?> msg, boolean release, Http2Stream stream)

Set final headers and fire a channel read event

Parameters
ctx:ChannelHandlerContext

The context to fire the event on

msg:FullHttpMessage<?>

The message to send

release:boolean

true to call release on the value if it is present. false to not call release.

stream:Http2Stream

the stream of the message which is being fired

getMessageback to summary
protected final FullHttpMessage<?> getMessage(Http2Stream stream)

Get the FullHttpMessage associated with stream.

Parameters
stream:Http2Stream

The stream to get the associated state from

Returns:FullHttpMessage<?>

The FullHttpMessage associated with stream.

newMessageback to summary
protected FullHttpMessage<?> newMessage(Http2Stream stream, Http2Headers headers, boolean validateHttpHeaders, BufferAllocator alloc) throws Http2Exception

Create a new FullHttpMessage based upon the current connection parameters

Parameters
stream:Http2Stream

The stream to create a message for

headers:Http2Headers

The headers associated with stream

validateHttpHeaders:boolean

  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
alloc:BufferAllocator

The BufferAllocator to use to generate the content of the message

Exceptions
Http2Exception:
If there is an error when creating FullHttpMessage from Http2Stream and Http2Headers
onDataReadback to summary
public int onDataRead(ChannelHandlerContext ctx, int streamId, Buffer data, int padding, boolean endOfStream) throws Http2Exception

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onDataRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onDataRead.

Doc from io.netty5.handler.codec.http2.Http2FrameListener.onDataRead.

Handles an inbound DATA frame.

Parameters
ctx:ChannelHandlerContext

the context from the handler where the frame was read.

streamId:int

the subject stream for the frame.

data:Buffer

payload buffer for the frame. This buffer will be closed by the codec when the method returns (the buffer will be inaccessible after the method call).

padding:int

additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).

endOfStream:boolean

Indicates whether this is the last frame to be sent from the remote endpoint for this stream.

Returns:int

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 of data + padding will effectively opt-out of application-level flow control for this frame. Returning a value less than the length of data + padding will defer the returning of the processed bytes, which the application must later return via Http2LocalFlowController#consumeBytes(Http2Stream, int). The returned value must be >= 0 and <= data.readableBytes() + padding.

Annotations
@Override
onHeadersReadback to summary
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endOfStream) throws Http2Exception

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onHeadersRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onHeadersRead.

Doc from io.netty5.handler.codec.http2.Http2FrameListener.onHeadersRead.

Handles an inbound HEADERS frame.

Only one of the following methods will be called for each HEADERS frame sequence. One will be called when the END_HEADERS flag has been received.

To say it another way; the Http2Headers will contain all of the headers for the current message exchange step (additional queuing is not necessary).

Parameters
ctx:ChannelHandlerContext

the context from the handler where the frame was read.

streamId:int

the subject stream for the frame.

headers:Http2Headers

the received headers.

padding:int

additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).

endOfStream:boolean

Indicates whether this is the last frame to be sent from the remote endpoint for this stream.

Annotations
@Override
onHeadersReadback to summary
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream) throws Http2Exception

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onHeadersRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onHeadersRead.

Doc from io.netty5.handler.codec.http2.Http2FrameListener.onHeadersRead.

Handles an inbound HEADERS frame with priority information specified. Only called if END_HEADERS encountered.

Only one of the following methods will be called for each HEADERS frame sequence. One will be called when the END_HEADERS flag has been received.

To say it another way; the Http2Headers will contain all of the headers for the current message exchange step (additional queuing is not necessary).

Parameters
ctx:ChannelHandlerContext

the context from the handler where the frame was read.

streamId:int

the subject stream for the frame.

headers:Http2Headers

the received headers.

streamDependency:int

the stream on which this stream depends, or 0 if dependent on the connection.

weight:short

the new weight for the stream.

exclusive:boolean

whether or not the stream should be the exclusive dependent of its parent.

padding:int

additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).

endOfStream:boolean

Indicates whether this is the last frame to be sent from the remote endpoint for this stream.

Annotations
@Override
onPushPromiseReadback to summary
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onPushPromiseRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onPushPromiseRead.

Doc from io.netty5.handler.codec.http2.Http2FrameListener.onPushPromiseRead.

Handles an inbound PUSH_PROMISE frame. Only called if END_HEADERS encountered.

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 HEADERS frame sequence. One will be called when the END_HEADERS flag has been received.

To say it another way; the Http2Headers will contain all of the headers for the current message exchange step (additional queuing is not necessary).

Parameters
ctx:ChannelHandlerContext

the context from the handler where the frame was read.

streamId:int

the stream the frame was sent on.

promisedStreamId:int

the ID of the promised stream.

headers:Http2Headers

the received headers.

padding:int

additional bytes that should be added to obscure the true content size. Must be between 0 and 256 (inclusive).

Annotations
@Override
onRstStreamReadback to summary
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onRstStreamRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onRstStreamRead.

Doc from io.netty5.handler.codec.http2.Http2FrameListener.onRstStreamRead.

Handles an inbound RST_STREAM frame.

Parameters
ctx:ChannelHandlerContext

the context from the handler where the frame was read.

streamId:int

the stream that is terminating.

errorCode:long

the error code identifying the type of failure.

Annotations
@Override
onRstStreamReadback to summary
protected void onRstStreamRead(Http2Stream stream, FullHttpMessage<?> msg)

Called if a RST_STREAM is received but we have some data for that stream.

onSettingsReadback to summary
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onSettingsRead.

Implements io.netty5.handler.codec.http2.Http2FrameListener.onSettingsRead.

Doc from io.netty5.handler.codec.http2.Http2FrameListener.onSettingsRead.

Handles an inbound SETTINGS frame.

Parameters
ctx:ChannelHandlerContext

the context from the handler where the frame was read.

settings:Http2Settings

the settings received from the remote endpoint.

Annotations
@Override
onStreamRemovedback to summary
public void onStreamRemoved(Http2Stream stream)

Overrides io.netty5.handler.codec.http2.Http2EventAdapter.onStreamRemoved.

Implements io.netty5.handler.codec.http2.Http2Connection.Listener.onStreamRemoved.

Doc from io.netty5.handler.codec.http2.Http2Connection.Listener.onStreamRemoved.

Notifies the listener that the given stream has now been removed from the connection and will no longer be returned via Http2Connection#stream(int). The connection may maintain inactive streams for some time before removing them.

If a RuntimeException is thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.

Annotations
@Override
processHeadersBeginback to summary
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:ChannelHandlerContext

The context for which this message has been received. Used to send informational header if detected.

stream:Http2Stream

The stream the headers apply to

headers:Http2Headers

The headers to process

endOfStream:boolean

true if the stream has received the end of stream flag

allowAppend:boolean

  • true if headers will be appended if the stream already exists.
  • if false and the stream already exists this method returns null.
appendToTrailer:boolean

  • true if a message stream already exists then the headers should be added to the trailing headers.
  • false then appends will be done to the initial headers.
Returns:FullHttpMessage<?>

The object used to track the stream corresponding to stream. null if allowAppend is false and the stream already exists.

Exceptions
Http2Exception:
If the stream id is not in the correct state to process the headers request
processHeadersEndback to summary
private void processHeadersEnd(ChannelHandlerContext ctx, Http2Stream stream, FullHttpMessage<?> msg, boolean endOfStream)

After HTTP/2 headers have been processed by processHeadersBegin this method either sends the result up the pipeline or retains the message for future processing.

Parameters
ctx:ChannelHandlerContext

The context for which this message has been received

stream:Http2Stream

The stream the objAccumulator corresponds to

msg:FullHttpMessage<?>

The object which represents all headers/data for corresponding to stream

endOfStream:boolean

true if this is the last event for the stream

putMessageback to summary
protected final void putMessage(Http2Stream stream, FullHttpMessage<?> message)

Make message be the state associated with stream.

Parameters
stream:Http2Stream

The stream which message is associated with.

message:FullHttpMessage<?>

The message which contains the HTTP semantics.

removeMessageback to summary
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:Http2Stream

The stream to remove associated state with

release:boolean

true to call release on the value if it is present. false to not call release.

io.netty5.handler.codec.http2 back to summary

private Interface InboundHttp2ToHttpAdapter.ImmediateSendDetector


Allows messages to be sent up the pipeline before the next phase in the HTTP message flow is detected.

Method Summary

Modifier and TypeMethod and Description
public FullHttpMessage<?>

Returns:

A modified copy of the msg or null if a copy is not needed.
copyIfNeeded
(BufferAllocator
The BufferAllocator that can be used to allocate
allocator
,
FullHttpMessage<?>
The message which has just been sent due to mustSendImmediately(FullHttpMessage)
msg
)

Determine if a copy must be made after an immediate send happens.

public boolean

Returns:

true if the message should be sent immediately {@code false) if we should wait for the end of the stream
mustSendImmediately
(FullHttpMessage<?>
The response to test
msg
)

Determine if the response should be sent immediately, or wait for the end of the stream

Method Detail

copyIfNeededback to summary
public FullHttpMessage<?> copyIfNeeded(BufferAllocator allocator, FullHttpMessage<?> msg)

Determine if a copy must be made after an immediate send happens.

An example of this use case is if a request is received with a 'Expect: 100-continue' header. The message will be sent immediately, and the data will be queued and sent at the end of the stream.

Parameters
allocator:BufferAllocator

The BufferAllocator that can be used to allocate

msg:FullHttpMessage<?>

The message which has just been sent due to mustSendImmediately(FullHttpMessage)

Returns:FullHttpMessage<?>

A modified copy of the msg or null if a copy is not needed.

mustSendImmediatelyback to summary
public boolean mustSendImmediately(FullHttpMessage<?> msg)

Determine if the response should be sent immediately, or wait for the end of the stream

Parameters
msg:FullHttpMessage<?>

The response to test

Returns:boolean

true if the message should be sent immediately {@code false) if we should wait for the end of the stream