A message that has a known length at the time of construction uses the format shown in Figure 1.¶
Figure 1: Known-Length Message
That is, a known-length message consists of a framing indicator, a block of control data that is formatted according to the value of the framing indicator, a header section with a length prefix, binary content with a length prefix, and a trailer section with a length prefix.¶
Response messages that contain informational status codes result in a different structure; see Section 3.5.1.¶
Fields in the header and trailer sections consist of a length-prefixed name and length-prefixed value. Both name and value are sequences of bytes that cannot be zero length.¶
The format allows for the message to be truncated before any of the length prefixes that precede the field sections or content. This reduces the overall message size. A message that is truncated at any other point is invalid; see Section 4.¶
The variable-length integer encoding means that there is a limit of 2^62-1 bytes for each field section and the message content.¶
A message that is constructed without encoding a known length for each section uses the format shown in Figure 2:¶
Figure 2: Indeterminate-Length Message
That is, an indeterminate length consists of a framing indicator, a block of control data that is formatted according to the value of the framing indicator, a header section that is terminated by a zero value, any number of non-zero-length chunks of binary content, a zero value, and a trailer section that is terminated by a zero value.¶
Response messages that contain informational status codes result in a different structure; see Section 3.5.1.¶
Indeterminate-length messages can be truncated in a similar way as known-length messages. Truncation occurs after the control data, or after the Content Terminator field that ends a field section or sequence of content chunks. A message that is truncated at any other point is invalid; see Section 4.¶
Indeterminate-length messages use the same encoding for field lines as known-length messages; see Section 3.6.¶
The control data for a request message includes four values that correspond to the values of the :method, :scheme, :authority, and :path pseudo-header fields described in HTTP/2 (Section 8.3.1 of [H2]). These fields are encoded, each with a length prefix, in the order listed.¶
The rules in Section 8.3 of [H2] for constructing pseudo-header fields apply to the construction of these values. However, where the :authority pseudo-header field might be omitted in HTTP/2, a zero-length value is encoded instead.¶
The format of request control data is shown in Figure 3.¶
Figure 3: Format of Request Control Data
Header and trailer sections consist of zero or more field lines; see Section 5 of [HTTP]. The format of a field section depends on whether the message is known- or intermediate-length.¶
Each field line includes a name and a value. Both the name and value are sequences of bytes, with the name including at least one byte. The format of a field line is shown in Figure 6.¶
Figure 6: Format of a Field Line
For field names, byte values that are not permitted in an HTTP field name cause the message to be invalid; see Section 5.1 of [HTTP] for a definition of what is valid and Section 4 for handling of invalid messages.¶
Field names and values MUST be constructed and validated according to the rules of Section 8.2.1 of [H2]. A recipient MUST treat a message that contains field values that would cause an HTTP/2 message to be malformed (Section 8.1.1 of [H2]) as invalid; see Section 4.¶
The same field name can be repeated in multiple field lines; see Section 5.2 of [HTTP] for the semantics of repeated field names and rules for combining values.¶
Like HTTP/2, this format has an exception for the combination of multiple instances of the Cookie field. Instances of fields with the ASCII-encoded value of cookie are combined using a semicolon octet (0x3b) rather than a comma; see Section 8.2.3 of [H2].¶
This format provides fixed locations for content that would be carried in HTTP/2 pseudo-fields. Therefore, there is no need to include field lines containing a name of :method, :scheme, :authority, :path, or :status. Fields that contain one of these names cause the message to be invalid; see Section 4. Pseudo-fields that are defined by protocol extensions MAY be included. Field lines containing pseudo-fields MUST precede other field lines; a message that contains a pseudo-field after any other field is invalid; see Section 4.¶
The content of messages is a sequence of bytes of any length. Though a known-length message has a limit, this limit is large enough that it is unlikely to be a practical limitation. There is no limit to the size of content in an indeterminate length message.¶
Omitting content by truncating a message is only possible if the content is zero-length.¶