Top Inners Fields Constructors Methods
org.apache.coyote.http2

pack-priv Class Http2Parser

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.coyote.http2.Http2AsyncParser
Imports
java.io.BufferedReader, .ByteArrayInputStream, .IOException, .InputStreamReader, .Reader, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, jakarta.servlet.http.WebConnection, org.apache.coyote.ProtocolException, org.apache.coyote.http2.HpackDecoder.HeaderEmitter, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.buf.ByteBufferUtils, org.apache.tomcat.util.http.parser.Priority, org.apache.tomcat.util.res.StringManager

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
Http2Parser.Input

Interface that must be implemented by the source of data for the parser.

pack-priv static interface
Http2Parser.Output

Interface that must be implemented to receive notifications from the parser as it processes incoming frames.

Field Summary

Modifier and TypeField and Description
pack-priv static final byte[]
protected final String
private final byte[]
private volatile ByteBuffer
private volatile int
private volatile boolean
private volatile HpackDecoder
protected final Http2Parser.Input
protected static final Log
private final Http2Parser.Output
protected static final StringManager

Constructor Summary

AccessConstructor and Description
pack-priv
Http2Parser(String connectionId, Http2Parser.Input input, Http2Parser.Output output)

Method Summary

Modifier and TypeMethod and Description
protected void
onHeadersComplete(int streamId)

pack-priv void
readConnectionPreface(WebConnection
The connection
webConnection
,
Stream
The current stream
stream
)

Read and validate the connection preface from input using blocking IO.

protected void
readContinuationFrame(int streamId, int flags, int payloadSize, ByteBuffer buffer)

protected void
readDataFrame(int streamId, int flags, int payloadSize, ByteBuffer buffer)

pack-priv boolean

Returns:

true if a frame was read otherwise false
readFrame
(boolean
Should this method block until a frame is available if no frame is available immediately?
block
)
Deprecated Unused. Will be removed in Tomcat 11 onwards.

Read and process a single frame.

pack-priv boolean

Returns:

true if a frame was read otherwise false
readFrame
()

Read and process a single frame.

protected boolean
readFrame(boolean block, FrameType expected)

protected void
readGoawayFrame(int payloadSize, ByteBuffer buffer)

protected void
readHeaderPayload(int streamId, int payloadSize, ByteBuffer buffer)

protected void
readHeadersFrame(int streamId, int flags, int payloadSize, ByteBuffer buffer)

protected void
readPingFrame(int flags, ByteBuffer buffer)

protected void
readPriorityFrame(int streamId, ByteBuffer buffer)

protected void
readPriorityUpdateFrame(int payloadSize, ByteBuffer buffer)

protected void
readPushPromiseFrame(int
The pushed stream
streamId
,
int
The flags set in the frame header
flags
,
int
The size of the payload in bytes
payloadSize
,
ByteBuffer
The payload, if available
buffer
)

This default server side implementation always throws an exception.

protected void
readRstFrame(int streamId, ByteBuffer buffer)

protected void
readSettingsFrame(int flags, int payloadSize, ByteBuffer buffer)

protected void
readUnknownFrame(int streamId, int frameTypeId, int flags, int payloadSize, ByteBuffer buffer)

protected void
readWindowUpdateFrame(int streamId, ByteBuffer buffer)

protected void
swallowPayload(int
Stream being swallowed
streamId
,
int
Type of HTTP/2 frame for which the bytes will be swallowed
frameTypeId
,
int
Number of bytes to swallow
len
,
boolean
Are the bytes to be swallowed padding bytes?
isPadding
,
ByteBuffer
Used with Http2AsyncParser to access the data that has already been read
byteBuffer
)

Swallow some or all of the bytes from the payload of an HTTP/2 frame.

protected void
validateFrame(FrameType expected, FrameType frameType, int streamId, int flags, int payloadSize)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLIENT_PREFACE_STARTback to summary
pack-priv static final byte[] CLIENT_PREFACE_START
connectionIdback to summary
protected final String connectionId
frameHeaderBufferback to summary
private final byte[] frameHeaderBuffer
headerReadBufferback to summary
private volatile ByteBuffer headerReadBuffer
headersCurrentStreamback to summary
private volatile int headersCurrentStream
headersEndStreamback to summary
private volatile boolean headersEndStream
hpackDecoderback to summary
private volatile HpackDecoder hpackDecoder
inputback to summary
protected final Http2Parser.Input input
logback to summary
protected static final Log log
outputback to summary
private final Http2Parser.Output output
smback to summary
protected static final StringManager sm

Constructor Detail

Http2Parserback to summary
pack-priv Http2Parser(String connectionId, Http2Parser.Input input, Http2Parser.Output output)

Method Detail

onHeadersCompleteback to summary
protected void onHeadersComplete(int streamId) throws Http2Exception
readConnectionPrefaceback to summary
pack-priv void readConnectionPreface(WebConnection webConnection, Stream stream) throws Http2Exception

Read and validate the connection preface from input using blocking IO.

Parameters
webConnection:WebConnection

The connection

stream:Stream

The current stream

readContinuationFrameback to summary
protected void readContinuationFrame(int streamId, int flags, int payloadSize, ByteBuffer buffer) throws Http2Exception, IOException
readDataFrameback to summary
protected void readDataFrame(int streamId, int flags, int payloadSize, ByteBuffer buffer) throws Http2Exception, IOException
readFrameback to summary
pack-priv boolean readFrame(boolean block) throws Http2Exception, IOException

Deprecated

Unused. Will be removed in Tomcat 11 onwards.

Read and process a single frame. Once the start of a frame is read, the remainder will be read using blocking IO.

Parameters
block:boolean

Should this method block until a frame is available if no frame is available immediately?

Returns:boolean

true if a frame was read otherwise false

Annotations
@Deprecated
Exceptions
IOException:
If an IO error occurs while trying to read a frame
readFrameback to summary
pack-priv boolean readFrame() throws Http2Exception, IOException

Read and process a single frame. The initial read is non-blocking to determine if a frame is present. Once the start of a frame is read, the remainder will be read using blocking IO.

Returns:boolean

true if a frame was read otherwise false

Exceptions
IOException:
If an IO error occurs while trying to read a frame
readFrameback to summary
protected boolean readFrame(boolean block, FrameType expected) throws IOException, Http2Exception
readGoawayFrameback to summary
protected void readGoawayFrame(int payloadSize, ByteBuffer buffer) throws IOException
readHeaderPayloadback to summary
protected void readHeaderPayload(int streamId, int payloadSize, ByteBuffer buffer) throws Http2Exception, IOException
readHeadersFrameback to summary
protected void readHeadersFrame(int streamId, int flags, int payloadSize, ByteBuffer buffer) throws Http2Exception, IOException
readPingFrameback to summary
protected void readPingFrame(int flags, ByteBuffer buffer) throws IOException
readPriorityFrameback to summary
protected void readPriorityFrame(int streamId, ByteBuffer buffer) throws IOException
readPriorityUpdateFrameback to summary
protected void readPriorityUpdateFrame(int payloadSize, ByteBuffer buffer) throws Http2Exception, IOException
readPushPromiseFrameback to summary
protected void readPushPromiseFrame(int streamId, int flags, int payloadSize, ByteBuffer buffer) throws Http2Exception, IOException

This default server side implementation always throws an exception. If re-used for client side parsing, this method should be overridden with an appropriate implementation.

Parameters
streamId:int

The pushed stream

flags:int

The flags set in the frame header

payloadSize:int

The size of the payload in bytes

buffer:ByteBuffer

The payload, if available

Exceptions
Http2Exception:
Always
IOException:
May be thrown by sub-classes that parse this frame
readRstFrameback to summary
protected void readRstFrame(int streamId, ByteBuffer buffer) throws Http2Exception, IOException
readSettingsFrameback to summary
protected void readSettingsFrame(int flags, int payloadSize, ByteBuffer buffer) throws Http2Exception, IOException
readUnknownFrameback to summary
protected void readUnknownFrame(int streamId, int frameTypeId, int flags, int payloadSize, ByteBuffer buffer) throws IOException
readWindowUpdateFrameback to summary
protected void readWindowUpdateFrame(int streamId, ByteBuffer buffer) throws Http2Exception, IOException
swallowPayloadback to summary
protected void swallowPayload(int streamId, int frameTypeId, int len, boolean isPadding, ByteBuffer byteBuffer) throws IOException, ConnectionException

Swallow some or all of the bytes from the payload of an HTTP/2 frame.

Parameters
streamId:int

Stream being swallowed

frameTypeId:int

Type of HTTP/2 frame for which the bytes will be swallowed

len:int

Number of bytes to swallow

isPadding:boolean

Are the bytes to be swallowed padding bytes?

byteBuffer:ByteBuffer

Used with Http2AsyncParser to access the data that has already been read

Exceptions
IOException:
If an I/O error occurs reading additional bytes into the input buffer.
ConnectionException:
If the swallowed bytes are expected to have a value of zero but do not
validateFrameback to summary
protected void validateFrame(FrameType expected, FrameType frameType, int streamId, int flags, int payloadSize) throws Http2Exception
org.apache.coyote.http2 back to summary

pack-priv Interface Http2Parser.Input

Known Direct Implementers
org.apache.coyote.http2.Http2UpgradeHandler

Interface that must be implemented by the source of data for the parser.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the buffer was filled otherwise false
fill
(boolean
Should the first read into the provided buffer be a blocking read or not.
block
,
byte[]
Buffer to fill
data
,
int
Position in buffer to start writing
offset
,
int
Number of bytes to read
length
)

Fill the given array with data unless non-blocking is requested and no data is available.

public default boolean
fill(boolean block, byte[] data)

public default boolean
fill(boolean block, ByteBuffer data, int len)

public int

Method Detail

fillback to summary
public boolean fill(boolean block, byte[] data, int offset, int length) throws IOException

Fill the given array with data unless non-blocking is requested and no data is available. If any data is available then the buffer will be filled using blocking I/O.

Parameters
block:boolean

Should the first read into the provided buffer be a blocking read or not.

data:byte[]

Buffer to fill

offset:int

Position in buffer to start writing

length:int

Number of bytes to read

Returns:boolean

true if the buffer was filled otherwise false

Exceptions
IOException:
If an I/O occurred while obtaining data with which to fill the buffer
fillback to summary
public default boolean fill(boolean block, byte[] data) throws IOException
fillback to summary
public default boolean fill(boolean block, ByteBuffer data, int len) throws IOException
getMaxFrameSizeback to summary
public int getMaxFrameSize()
org.apache.coyote.http2 back to summary

pack-priv Interface Http2Parser.Output

Known Direct Implementers
org.apache.coyote.http2.Http2UpgradeHandler

Interface that must be implemented to receive notifications from the parser as it processes incoming frames.

Method Summary

Modifier and TypeMethod and Description
public void
endRequestBodyFrame(int streamId, int dataLength)

public HpackDecoder
public void
goaway(int lastStreamId, long errorCode, String debugData)

public void
headersContinue(int payloadSize, boolean endOfHeaders)

public void
headersEnd(int streamId, boolean endOfStream)

public HpackDecoder.HeaderEmitter
headersStart(int streamId, boolean headersEndStream)

public void
public void
incrementWindowSize(int streamId, int increment)

public void
onSwallowedDataFramePayload(int
The stream on which the payload that has been swallowed was received
streamId
,
int
The number of bytes that the parser swallowed.
swallowedDataBytesCount
)

Notification triggered when the parser swallows some or all of a DATA frame payload without writing it to the ByteBuffer returned by startRequestBodyFrame(int, int, boolean).

public void
onSwallowedUnknownFrame(int
The stream on which the swallowed frame was received
streamId
,
int
The (unrecognised) type of swallowed frame
frameTypeId
,
int
The flags set in the header of the swallowed frame
flags
,
int
The payload size of the swallowed frame
size
)

Notification triggered when the parser swallows the payload of an unknown frame.

public void
pingReceive(byte[] payload, boolean ack)

public void
priorityUpdate(int prioritizedStreamID, Priority p)

public void
receivedEndOfStream(int streamId)

public void
reset(int streamId, long errorCode)

public void
setting(Setting setting, long value)

public void
settingsEnd(boolean ack)

public ByteBuffer
startRequestBodyFrame(int streamId, int payloadSize, boolean endOfStream)

Method Detail

endRequestBodyFrameback to summary
public void endRequestBodyFrame(int streamId, int dataLength) throws Http2Exception, IOException
getHpackDecoderback to summary
public HpackDecoder getHpackDecoder()
goawayback to summary
public void goaway(int lastStreamId, long errorCode, String debugData)
headersContinueback to summary
public void headersContinue(int payloadSize, boolean endOfHeaders)
headersEndback to summary
public void headersEnd(int streamId, boolean endOfStream) throws Http2Exception
headersStartback to summary
public HpackDecoder.HeaderEmitter headersStart(int streamId, boolean headersEndStream) throws Http2Exception, IOException
increaseOverheadCountback to summary
public void increaseOverheadCount(FrameType frameType)
incrementWindowSizeback to summary
public void incrementWindowSize(int streamId, int increment) throws Http2Exception
onSwallowedDataFramePayloadback to summary
public void onSwallowedDataFramePayload(int streamId, int swallowedDataBytesCount) throws ConnectionException, IOException

Notification triggered when the parser swallows some or all of a DATA frame payload without writing it to the ByteBuffer returned by startRequestBodyFrame(int, int, boolean).

Parameters
streamId:int

The stream on which the payload that has been swallowed was received

swallowedDataBytesCount:int

The number of bytes that the parser swallowed.

Exceptions
ConnectionException:
If an error fatal to the HTTP/2 connection occurs while swallowing the payload
IOException:
If an I/O occurred while swallowing the payload
onSwallowedUnknownFrameback to summary
public void onSwallowedUnknownFrame(int streamId, int frameTypeId, int flags, int size) throws IOException

Notification triggered when the parser swallows the payload of an unknown frame.

Parameters
streamId:int

The stream on which the swallowed frame was received

frameTypeId:int

The (unrecognised) type of swallowed frame

flags:int

The flags set in the header of the swallowed frame

size:int

The payload size of the swallowed frame

Exceptions
IOException:
If an I/O occurred while swallowing the unknown frame
pingReceiveback to summary
public void pingReceive(byte[] payload, boolean ack) throws IOException
priorityUpdateback to summary
public void priorityUpdate(int prioritizedStreamID, Priority p) throws Http2Exception
receivedEndOfStreamback to summary
public void receivedEndOfStream(int streamId) throws ConnectionException
resetback to summary
public void reset(int streamId, long errorCode) throws Http2Exception
settingback to summary
public void setting(Setting setting, long value) throws ConnectionException
settingsEndback to summary
public void settingsEnd(boolean ack) throws IOException
startRequestBodyFrameback to summary
public ByteBuffer startRequestBodyFrame(int streamId, int payloadSize, boolean endOfStream) throws Http2Exception