跳到主要内容

3. HTTP/3 上的 WebSockets Upgrade (WebSockets Upgrade over HTTP/3)

[RFC8441] 定义了一种机制, 用于在 HTTP/2 connection 的单个 stream 上运行 WebSocket Protocol [RFC6455]. 它定义了 Extended CONNECT method, 该方法规定了新的 ":protocol" pseudo-header field, 以及 ":path" 和 ":authority" pseudo-header fields 的新语义. 它还定义了服务器发送的一个新的 HTTP/2 setting, 用于允许客户端使用 Extended CONNECT.

pseudo-header fields 和 setting 的语义与 [RFC8441] 中定义的 HTTP/2 语义相同. [HTTP/3] 的 Appendix A.3 要求 HTTP/3 settings 必须单独为 HTTP/3 注册. SETTINGS_ENABLE_CONNECT_PROTOCOL 值为 0x08 (decimal 8), 与 HTTP/2 中相同.

如果服务器宣告支持 Extended CONNECT, 但收到的 Extended CONNECT request 中 ":protocol" 值未知或不受支持, 则服务器 SHOULD 使用 501 (Not Implemented) status code (Section 15.6.2 of [HTTP]) 响应该请求. 服务器 MAY 通过 "problem details" response [RFC7807] 提供更多信息.

HTTP/3 stream closure 也类似于 [RFC6455] 的 TCP connection closure. 有序的 TCP-level closures 表示为 stream 上的 FIN bit (Section 4.4 of [HTTP/3]). RST exceptions 表示为类型为 H3_REQUEST_CANCELLED (Section 8.1 of [HTTP/3]) 的 stream error (Section 8 of [HTTP/3]).