2. HTTP Datagrams (HTTP 数据报)
HTTP Datagrams (HTTP 数据报) 是一种在 HTTP 连接内传递双向且可能不可靠的数据报的约定, 在可能的情况下支持多路复用。所有 HTTP Datagrams 都与一个 HTTP 请求相关联。
When HTTP Datagrams are conveyed on an HTTP/3 connection, the QUIC DATAGRAM frame can be used to provide demultiplexing and unreliable delivery; see Section 2.1. Negotiating the use of QUIC DATAGRAM frames for HTTP Datagrams is achieved via the exchange of HTTP/3 settings; see Section 2.1.1.
当 HTTP Datagrams 在 HTTP/3 连接上传送时, QUIC DATAGRAM frame (QUIC DATAGRAM 帧) 可用于提供解复用和不可靠传递; 请参阅第 2.1 节。通过交换 HTTP/3 settings (HTTP/3 设置) 来协商使用 QUIC DATAGRAM frames 传送 HTTP Datagrams; 请参阅第 2.1.1 节。
When running over HTTP/2, demultiplexing is provided by the HTTP/2 framing layer, but unreliable delivery is unavailable. HTTP Datagrams are negotiated and conveyed using the Capsule Protocol; see Section 3.5.
当运行在 HTTP/2 上时, 解复用由 HTTP/2 framing layer (HTTP/2 帧层) 提供, 但不可靠传递不可用。HTTP Datagrams 通过 Capsule Protocol (封装协议) 进行协商和传送; 请参阅第 3.5 节。
When running over HTTP/1.x, requests are strictly serialized in the connection; therefore, demultiplexing is not available. Unreliable delivery is likewise not available. HTTP Datagrams are negotiated and conveyed using the Capsule Protocol; see Section 3.5.
当运行在 HTTP/1.x 上时, 请求在连接中严格串行化; 因此, 解复用不可用。不可靠传递同样不可用。HTTP Datagrams 通过 Capsule Protocol (封装协议) 进行协商和传送; 请参阅第 3.5 节。
HTTP Datagrams MUST only be sent with an association to an HTTP request that explicitly supports them. For example, existing HTTP methods GET and POST do not define semantics for associated HTTP Datagrams; therefore, HTTP Datagrams associated with GET or POST request streams cannot be sent.
HTTP Datagrams 必须仅与明确支持它们的 HTTP 请求相关联发送。例如, 现有的 HTTP 方法 GET 和 POST 没有为关联的 HTTP Datagrams 定义语义; 因此, 不能发送与 GET 或 POST 请求流相关联的 HTTP Datagrams。
If an HTTP Datagram is received and it is associated with a request that has no known semantics for HTTP Datagrams, the receiver MUST terminate the request. If HTTP/3 is in use, the request stream MUST be aborted with H3_DATAGRAM_ERROR (0x33). HTTP extensions MAY override these requirements by defining a negotiation mechanism and semantics for HTTP Datagrams.
如果接收到一个 HTTP Datagram, 且它与一个没有已知 HTTP Datagrams 语义的请求相关联, 接收方必须终止该请求。如果正在使用 HTTP/3, 请求流必须以 H3_DATAGRAM_ERROR (0x33) 中止。HTTP 扩展可以通过定义协商机制和 HTTP Datagrams 的语义来覆盖这些要求。
2.1. HTTP/3 Datagrams (HTTP/3 数据报)
When used with HTTP/3, the Datagram Data field of QUIC DATAGRAM frames uses the following format:
当与 HTTP/3 一起使用时, QUIC DATAGRAM frames 的 Datagram Data (数据报数据) 字段使用以下格式:
HTTP/3 Datagram {
Quarter Stream ID (i),
HTTP Datagram Payload (..),
}
Figure 1: HTTP/3 Datagram Format
Quarter Stream ID: A variable-length integer that contains the value of the client-initiated bidirectional stream that this datagram is associated with divided by four (the division by four stems from the fact that HTTP requests are sent on client-initiated bidirectional streams, which have stream IDs that are divisible by four). The largest legal QUIC stream ID value is 2^62-1, so the largest legal value of the Quarter Stream ID field is 2^60-1. Receipt of an HTTP/3 Datagram that includes a larger value MUST be treated as an HTTP/3 connection error of type H3_DATAGRAM_ERROR (0x33).
Quarter Stream ID: 一个变长整数, 包含此数据报关联的客户端发起的双向流的值除以四 (除以四源于这样一个事实: HTTP 请求在客户端发起的双向流上发送, 这些流的 stream IDs (流 IDs) 可被四整除)。最大的合法 QUIC stream ID (流 ID) 值是 2^62-1, 因此 Quarter Stream ID 字段的最大合法值是 2^60-1。接收到包含更大值的 HTTP/3 Datagram 必须被视为类型为 H3_DATAGRAM_ERROR (0x33) 的 HTTP/3 连接错误。
HTTP Datagram Payload: The payload of the datagram, whose semantics are defined by the extension that is using HTTP Datagrams. Note that this field can be empty.
HTTP Datagram Payload: 数据报的有效载荷, 其语义由使用 HTTP Datagrams 的扩展定义。注意此字段可以为空。
Receipt of a QUIC DATAGRAM frame whose payload is too short to allow parsing the Quarter Stream ID field MUST be treated as an HTTP/3 connection error of type H3_DATAGRAM_ERROR (0x33).
接收到有效载荷太短而无法解析 Quarter Stream ID 字段的 QUIC DATAGRAM frame (QUIC DATAGRAM 帧) 必须被视为类型为 H3_DATAGRAM_ERROR (0x33) 的 HTTP/3 连接错误。
HTTP/3 Datagrams MUST NOT be sent unless the corresponding stream's send side is open. If a datagram is received after the corresponding stream's receive side is closed, the received datagrams MUST be silently dropped.
HTTP/3 Datagrams 绝对不能在相应流的发送侧未打开时发送。如果在相应流的接收侧关闭后接收到数据报, 接收到的数据报必须被静默丢弃。
If an HTTP/3 Datagram is received and its Quarter Stream ID field maps to a stream that has not yet been created, the receiver SHALL either drop that datagram silently or buffer it temporarily (on the order of a round trip) while awaiting the creation of the corresponding stream.
如果接收到一个 HTTP/3 Datagram, 且其 Quarter Stream ID 字段映射到一个尚未创建的流, 接收方应该静默丢弃该数据报或在等待相应流创建时临时缓冲它 (大约一个往返时间)。
If an HTTP/3 Datagram is received and its Quarter Stream ID field maps to a stream that cannot be created due to client-initiated bidirectional stream limits, it SHOULD be treated as an HTTP/3 connection error of type H3_ID_ERROR. Generating an error is not mandatory because the QUIC stream limit might be unknown to the HTTP/3 layer.
如果接收到一个 HTTP/3 Datagram, 且其 Quarter Stream ID 字段映射到一个由于客户端发起的双向流限制而无法创建的流, 它应该被视为类型为 H3_ID_ERROR 的 HTTP/3 连接错误。生成错误不是强制性的, 因为 QUIC stream limit (QUIC 流限制) 可能对 HTTP/3 层未知。
Prioritization of HTTP/3 Datagrams is not defined in this document. Future extensions MAY define how to prioritize datagrams and MAY define signaling to allow communicating prioritization preferences.
本文档未定义 HTTP/3 Datagrams 的优先级。未来的扩展可以定义如何对数据报进行优先级排序, 并可以定义信令以允许传达优先级偏好。
2.1.1. The SETTINGS_H3_DATAGRAM HTTP/3 Setting (SETTINGS_H3_DATAGRAM HTTP/3 设置)
An endpoint can indicate to its peer that it is willing to receive HTTP/3 Datagrams by sending the SETTINGS_H3_DATAGRAM (0x33) setting with a value of 1.
端点可以通过发送值为 1 的 SETTINGS_H3_DATAGRAM (0x33) 设置来向其对等方指示它愿意接收 HTTP/3 Datagrams。
The value of the SETTINGS_H3_DATAGRAM setting MUST be either 0 or 1. A value of 0 indicates that the implementation is not willing to receive HTTP Datagrams. If the SETTINGS_H3_DATAGRAM setting is received with a value that is neither 0 nor 1, the receiver MUST terminate the connection with error H3_SETTINGS_ERROR.
SETTINGS_H3_DATAGRAM 设置的值必须是 0 或 1。值为 0 表示实现不愿意接收 HTTP Datagrams。如果接收到的 SETTINGS_H3_DATAGRAM 设置的值既不是 0 也不是 1, 接收方必须以错误 H3_SETTINGS_ERROR 终止连接。
QUIC DATAGRAM frames MUST NOT be sent until the SETTINGS_H3_DATAGRAM setting has been both sent and received with a value of 1.
QUIC DATAGRAM frames 绝对不能在 SETTINGS_H3_DATAGRAM 设置已发送和接收且值为 1 之前发送。
When clients use 0-RTT, they MAY store the value of the server's SETTINGS_H3_DATAGRAM setting. Doing so allows the client to send QUIC DATAGRAM frames in 0-RTT packets. When servers decide to accept 0-RTT data, they MUST send a SETTINGS_H3_DATAGRAM setting greater than or equal to the value they sent to the client in the connection where they sent them the NewSessionTicket message. If a client stores the value of the SETTINGS_H3_DATAGRAM setting with their 0-RTT state, they MUST validate that the new value of the SETTINGS_H3_DATAGRAM setting sent by the server in the handshake is greater than or equal to the stored value; if not, the client MUST terminate the connection with error H3_SETTINGS_ERROR. In all cases, the maximum permitted value of the SETTINGS_H3_DATAGRAM setting parameter is 1.
当客户端使用 0-RTT 时, 它们可以存储服务器的 SETTINGS_H3_DATAGRAM 设置值。这样做允许客户端在 0-RTT 数据包中发送 QUIC DATAGRAM frames。当服务器决定接受 0-RTT 数据时, 它们必须发送大于或等于它们在发送 NewSessionTicket 消息的连接中发送给客户端的值的 SETTINGS_H3_DATAGRAM 设置。如果客户端将 SETTINGS_H3_DATAGRAM 设置的值与其 0-RTT 状态一起存储, 它们必须验证服务器在握手中发送的 SETTINGS_H3_DATAGRAM 设置的新值大于或等于存储的值; 如果不是, 客户端必须以错误 H3_SETTINGS_ERROR 终止连接。在所有情况下, SETTINGS_H3_DATAGRAM 设置参数的最大允许值为 1。
It is RECOMMENDED that implementations that support receiving HTTP/3 Datagrams always send the SETTINGS_H3_DATAGRAM setting with a value of 1, even if the application does not intend to use HTTP/3 Datagrams. This helps to avoid "sticking out"; see Section 4.
建议支持接收 HTTP/3 Datagrams 的实现始终发送值为 1 的 SETTINGS_H3_DATAGRAM 设置, 即使应用程序不打算使用 HTTP/3 Datagrams。这有助于避免 "sticking out" (脱颖而出); 请参阅第 4 节。
2.2. HTTP Datagrams Using Capsules (使用封装的 HTTP 数据报)
When HTTP/3 Datagrams are unavailable or undesirable, HTTP Datagrams can be sent using the Capsule Protocol; see Section 3.5.
当 HTTP/3 Datagrams 不可用或不希望使用时, HTTP Datagrams 可以使用 Capsule Protocol (封装协议) 发送; 请参阅第 3.5 节。