Package io.github.mahmoudimus.http3
Class Http3StreamValidator
java.lang.Object
io.github.mahmoudimus.http3.Http3StreamValidator
Checks which frames the peer may send on one stream, and in what order (RFC 9114 §4.1, §6.2.1,
§7.2). Feed it every frame read from the stream, then the end of the stream. One validator per
stream; not thread-safe.
- Control stream (
forControlStream(io.github.mahmoudimus.http3.Http3StreamValidator.Role)): SETTINGS first (else H3_MISSING_SETTINGS) and only once; no DATA, HEADERS or PUSH_PROMISE; MAX_PUSH_ID only from a client, never decreasing; GOAWAY never increasing, and from a server naming a client-initiated bidirectional stream; CANCEL_PUSH to a server within the MAX_PUSH_ID it received. Its end is a connection error H3_CLOSED_CRITICAL_STREAM. - Request stream (
forRequestStream(long, io.github.mahmoudimus.http3.Http3StreamValidator.Role)): HEADERS, then any number of DATA, then optionally trailing HEADERS, and nothing after that; a response may be preceded by interim (1xx) HEADERS, which the caller reports withinterimResponse(). PUSH_PROMISE only from a server, anywhere. No SETTINGS, GOAWAY, MAX_PUSH_ID or CANCEL_PUSH. A request stream that ends before its HEADERS is a stream error H3_REQUEST_INCOMPLETE. - Push stream (
forPushStream(long, io.github.mahmoudimus.http3.Http3StreamValidator.Role)): as a response on a request stream, without PUSH_PROMISE.
Frames of unknown and reserved types are allowed anywhere except before SETTINGS on the control stream. Wrong frames are connection errors H3_FRAME_UNEXPECTED.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe kind of stream a validator checks.static enumWhich end of the connection this endpoint is.static final classThe peer's unidirectional streams (RFC 9114 §6.2, RFC 9204 §4.2): at most one control stream, one QPACK encoder stream and one QPACK decoder stream, and push streams only from a server. -
Method Summary
Modifier and TypeMethodDescriptionstatic Http3StreamValidatorA validator for the peer's control stream.static Http3StreamValidatorforPushStream(long streamId, Http3StreamValidator.Role local) A validator for a push stream, after its push ID; only clients receive these.static Http3StreamValidatorforRequestStream(long streamId, Http3StreamValidator.Role local) A validator for the frames received on a request stream: a request whenlocalis the server, a response when it is the client.booleanWhether a complete header section has been received on a request or push stream.voidReports that the HEADERS just received held an interim (1xx) response, so another header section must follow (RFC 9114 §4.1).kind()The kind of stream this validator checks.voidReports the clean end of the stream.voidonFrame(long type) Checks the next frame by type alone.voidonFrame(Http3Frame frame) Checks the next frame, including the identifiers in GOAWAY, MAX_PUSH_ID and CANCEL_PUSH.booleanWhether the control stream's SETTINGS frame has arrived.booleanWhether trailers have been received on a request or push stream.
-
Method Details
-
forControlStream
A validator for the peer's control stream.- Parameters:
local- which end this endpoint is- Returns:
- the validator
-
forRequestStream
A validator for the frames received on a request stream: a request whenlocalis the server, a response when it is the client.- Parameters:
streamId- the streamlocal- which end this endpoint is- Returns:
- the validator
-
forPushStream
A validator for a push stream, after its push ID; only clients receive these.- Parameters:
streamId- the streamlocal- which end this endpoint is; onlyHttp3StreamValidator.Role.CLIENT- Returns:
- the validator
-
kind
The kind of stream this validator checks.- Returns:
- the kind
-
settingsReceived
public boolean settingsReceived()Whether the control stream's SETTINGS frame has arrived.- Returns:
- whether SETTINGS arrived
-
headersReceived
public boolean headersReceived()Whether a complete header section has been received on a request or push stream.- Returns:
- whether a header section arrived
-
trailersReceived
public boolean trailersReceived()Whether trailers have been received on a request or push stream.- Returns:
- whether trailers arrived
-
onFrame
Checks the next frame, including the identifiers in GOAWAY, MAX_PUSH_ID and CANCEL_PUSH.- Parameters:
frame- the frame- Throws:
Http3Exception- a connection error if the frame is not allowed here
-
onFrame
Checks the next frame by type alone.- Parameters:
type- the frame type- Throws:
Http3Exception- a connection error if the frame is not allowed here
-
interimResponse
public void interimResponse()Reports that the HEADERS just received held an interim (1xx) response, so another header section must follow (RFC 9114 §4.1). Only valid on a response, directly after its HEADERS.- Throws:
IllegalStateException- otherwise
-
onEndOfStream
Reports the clean end of the stream.- Throws:
Http3Exception- a connection error H3_CLOSED_CRITICAL_STREAM for the control stream; a stream error H3_REQUEST_INCOMPLETE for a request that ended before its header section, or H3_MESSAGE_ERROR for a response that did
-