Class OriginFrame

java.lang.Object
io.github.mahmoudimus.http2.OriginFrame

public final class OriginFrame extends Object
The ORIGIN frame (RFC 8336): a server names the origins it is authoritative for on the connection, such as https://b.example.com or https://b.example.com:8443, so a client may send requests for them there without consulting DNS.

It is an extension frame, not one of RFC 9113's types, so it travels as a Frame.Unknown of type FrameType.ORIGIN: FrameReader returns it when asked to (FrameReader.setDeliverOriginFrames(boolean)), and FrameWriter.writeFrame(Frame) writes the one frame(java.util.List<java.lang.String>) builds. Its payload is a sequence of Origin-Entry fields, each a 16-bit length and that many octets of an origin's ASCII serialization. It defines no flags, and one received on a stream other than 0 must be ignored (RFC 8336 section 2.1), as must one sent to a server.


 case Frame.Unknown u when OriginFrame.isOrigin(u) -> {
     try {
         originSet.addAll(OriginFrame.origins(u));
     } catch (IllegalArgumentException malformed) {
         // ignored, as any extension frame may be
     }
 }
 
  • Field Details

    • MAX_ORIGIN_LENGTH

      public static final int MAX_ORIGIN_LENGTH
      The longest origin an Origin-Entry can carry: its length is 16 bits.
      See Also:
  • Method Details

    • isOrigin

      public static boolean isOrigin(Frame frame)
      Whether frame is an ORIGIN frame a client acts on: of type FrameType.ORIGIN and on stream 0 (one on any other stream is ignored).
      Parameters:
      frame - any frame
      Returns:
      true for an ORIGIN frame on stream 0
    • origins

      public static List<String> origins(Frame.Unknown frame)
      The origins an ORIGIN frame names, in the order it names them.
      Parameters:
      frame - an ORIGIN frame
      Returns:
      the origins' ASCII serializations, as sent (an empty one stays empty)
      Throws:
      IllegalArgumentException - if the frame is not of type ORIGIN, or is malformed: an entry runs past the end of the payload, or holds non-ASCII octets
    • decode

      public static List<String> decode(byte[] payload)
      Reads an ORIGIN frame's payload.
      Parameters:
      payload - the frame's payload
      Returns:
      the origins' ASCII serializations, in order
      Throws:
      IllegalArgumentException - if an entry runs past the end of the payload, or holds non-ASCII octets
    • encode

      public static byte[] encode(List<String> origins)
      Builds an ORIGIN frame's payload.
      Parameters:
      origins - the origins' ASCII serializations, such as https://example.com
      Returns:
      the payload: each origin preceded by its 16-bit length
      Throws:
      IllegalArgumentException - if an origin is not ASCII or longer than MAX_ORIGIN_LENGTH octets
    • frame

      public static Frame.Unknown frame(List<String> origins)
      An ORIGIN frame naming origins, on stream 0 and without flags, for FrameWriter.writeFrame(Frame).
      Parameters:
      origins - the origins' ASCII serializations
      Returns:
      the frame
      Throws:
      IllegalArgumentException - as encode(java.util.List<java.lang.String>) does