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. Note that while the Known-Length Informational Response field is shown in Figure 1, it can only appear in response messages.¶
For a known-length encoding, the length prefix on field sections and content is a variable-length encoding of an integer. This integer is the number of bytes in the field section or content, not including the length field itself.¶
Fields in the header and trailer sections consist of a length-prefixed name and length-prefixed value; see Section 3.6.¶
The format allows for the message to be truncated before any of the length prefixes that precede the field sections or content; see Section 3.8.¶
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 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 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. Note that while the Indeterminate-Length Informational Response field is shown in Figure 2, it can only appear in response messages.¶
The indeterminate-length encoding only uses length prefixes for content blocks. Multiple length-prefixed portions of content can be included, each prefixed by a non-zero Chunk Length integer describing the number of bytes in the block. The Chunk Length is encoded as a variable-length integer.¶
Each Field Line in an Indeterminate-Length Field Section starts with a Name Length field. An Indeterminate-Length Field Section ends with a Content Terminator field. The zero value of the Content Terminator distinguishes it from the Name Length field, which cannot contain a value of 0.¶
Indeterminate-length messages can be truncated in a similar way as known-length messages; see Section 3.8.¶
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 contains the method and request target. That information is encoded as an ordered sequence of fields: Method, Scheme, Authority, Path. Each of these fields is prefixed with a length.¶
The values of these fields follow the rules in HTTP/2 (Section 8.3.1 of [HTTP/2]) that apply to the :method, :scheme, :authority, and :path pseudo-header fields respectively. 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 indeterminate-length.¶
Each field line includes a name and a value. Both the name and value are length-prefixed sequences of bytes. The field name length is 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. A recipient MUST treat a message that contains field values that would cause an HTTP/2 message to be malformed according to Section 8.2.1 of [HTTP/2] 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.¶
Fields that relate to connections (Section 7.6.1 of [HTTP]) cannot be used to produce the effect on a connection in this context. These fields SHOULD be removed when constructing a binary message. However, they do not cause a message to be invalid (Section 4); permitting these fields allows a binary message to capture the content of a messages that are exchanged in a protocol context.¶
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 [HTTP/2].¶
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.¶