Class Http3StreamValidator

java.lang.Object
io.github.mahmoudimus.http3.Http3StreamValidator

public final class Http3StreamValidator extends Object
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.

Frames of unknown and reserved types are allowed anywhere except before SETTINGS on the control stream. Wrong frames are connection errors H3_FRAME_UNEXPECTED.

  • Method Details

    • forControlStream

      public static Http3StreamValidator forControlStream(Http3StreamValidator.Role local)
      A validator for the peer's control stream.
      Parameters:
      local - which end this endpoint is
      Returns:
      the validator
    • forRequestStream

      public static Http3StreamValidator forRequestStream(long streamId, Http3StreamValidator.Role local)
      A validator for the frames received on a request stream: a request when local is the server, a response when it is the client.
      Parameters:
      streamId - the stream
      local - which end this endpoint is
      Returns:
      the validator
    • forPushStream

      public static Http3StreamValidator forPushStream(long streamId, Http3StreamValidator.Role local)
      A validator for a push stream, after its push ID; only clients receive these.
      Parameters:
      streamId - the stream
      local - which end this endpoint is; only Http3StreamValidator.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

      public void onFrame(Http3Frame frame) throws Http3Exception
      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

      public void onFrame(long type) throws Http3Exception
      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

      public void onEndOfStream() throws Http3Exception
      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