msgid ""
msgstr ""
"Project-Id-Version: Chinese (Simplified Han script) (Boost Beast Translation "
"(zh_Hans))\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-07-25 13:57+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: Chinese (Simplified Han script) <https://"
"insights.cppalliance.org/weblate/projects/boost-beast-documentation-zh_Hans/"
"doc-qbk-06-websocket-02-handshaking-qbk/zh_Hans/>\n"
"Language: zh_Hans\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 2026.5\n"

#. type: section title
#: 10
msgid "Handshaking"
msgstr "握手"

#. type: heading
#: 14
msgid "Client Role"
msgstr "客户端角色"

#. type: paragraph
#: 16
msgid ""
"A WebSocket session begins when a client sends the HTTP/1.1 [@https://"
"tools.ietf.org/html/rfc7230#section-6.7 Upgrade] request for [@https://"
"tools.ietf.org/html/rfc6455#section-1.3 WebSocket] on an established "
"connection, and the server sends an appropriate response indicating that the "
"request was accepted and that the connection has been upgraded. The Upgrade "
"request must include the [@https://tools.ietf.org/html/rfc7230#section-5.4 "
"Host] field, and the [@https://tools.ietf.org/html/rfc7230#section-5.3 "
"target] of the resource to request. A typical HTTP Upgrade request created "
"and sent by the implementation will look like this:"
msgstr ""
"WebSocket 会话的建立过程如下：客户端在已建立的连接上发送 HTTP/1.1 [@https://"
"tools.ietf.org/html/rfc7230#section-6.7 Upgrade] 请求，服务器则返回相应响应，"
"表示接受该升级请求。该 Upgrade 请求必须包含 [@https://tools.ietf.org/html/"
"rfc7230#section-5.4 Host] 字段以及所请求资源的 [@https://tools.ietf.org/html/"
"rfc7230#section-5.3 目标]。由实现创建并发送的典型 HTTP Upgrade 请求如下所示："

#. type: table title
#: 30
msgid "WebSocket HTTP Upgrade Request"
msgstr "WebSocket HTTP 升级请求"

#. type: table cell
#: 30
msgctxt "30"
msgid "Wire Format"
msgstr "线路格式"

#. type: table cell
#: 30
msgctxt "30"
msgid "Description"
msgstr "描述"

#. type: table code
#: 30
msgid ""
"GET / HTTP/1.1\n"
"Host: www.example.com\n"
"Upgrade: websocket\n"
"Connection: upgrade\n"
"Sec-WebSocket-Key: 2pGeTR0DsE4dfZs2pH+8MA==\n"
"Sec-WebSocket-Version: 13\n"
"User-Agent: Boost.Beast/216"
msgstr ""
"GET / HTTP/1.1\n"
"Host: www.example.com\n"
"Upgrade: websocket\n"
"Connection: upgrade\n"
"Sec-WebSocket-Key: 2pGeTR0DsE4dfZs2pH+8MA==\n"
"Sec-WebSocket-Version: 13\n"
"User-Agent: Boost.Beast/216"

#. type: table cell
#: 30
msgid ""
"The host and target parameters become part of the Host field and request-"
"target in the resulting HTTP request. The key is generated by the "
"implementation. Callers who wish to add, modify, or inspect fields may set "
"the ['decorator] option on the stream (described later)."
msgstr ""
"主机和目标参数会分别填入所生成的 HTTP 请求中，分别对应 Host 字段和请求目标。"
"密钥由实现自行生成。如果调用方需要添加、修改或检查字段，可以在流上设置修饰器"
"选项（详见下文）。"

#. type: paragraph
#: 50
msgid ""
"The [link beast.ref.boost__beast__websocket__stream `websocket::stream`] "
"member functions [link beast.ref.boost__beast__websocket__stream.handshake "
"`handshake`] and [link "
"beast.ref.boost__beast__websocket__stream.async_handshake `async_handshake`] "
"are used to send the request with the required host and target strings. This "
"code connects to the IP address returned from a hostname lookup, then "
"performs the WebSocket handshake in the client role."
msgstr ""
"[link beast.ref.boost__beast__websocket__stream `websocket::stream`] 的成员函"
"数 [link beast.ref.boost__beast__websocket__stream.handshake `handshake`] 和 "
"[link beast.ref.boost__beast__websocket__stream.async_handshake "
"`async_handshake`] 用于发送包含所需主机和目标字符串的请求。以下代码先连接到通"
"过主机名解析获得的 IP 地址，然后以客户端角色执行 WebSocket 握手。"

#. type: paragraph
#: 61
msgid ""
"When a client receives an HTTP Upgrade response from the server indicating a "
"successful upgrade, the caller may wish to perform additional validation on "
"the received HTTP response message. For example, to check that the response "
"to a basic authentication challenge is valid. To achieve this, overloads of "
"the handshake member function allow the caller to store the received HTTP "
"message in an output reference argument of type [link "
"beast.ref.boost__beast__websocket__response_type `response_type`] as follows:"
msgstr ""
"当客户端收到服务器返回的表示升级成功的 HTTP Upgrade 响应时，调用方可能希望对"
"收到的 HTTP 响应消息进行额外验证。例如，检查基本认证质询的响应是否有效。为此"
"，handshake 成员函数的重载版本允许调用方将收到的 HTTP 消息存储到一个输出引用"
"参数中，该参数类型为 [link beast.ref.boost__beast__websocket__response_type "
"`response_type`]，用法如下："

#. type: heading
#: 74
msgid "Server Role"
msgstr "服务器角色"

#. type: paragraph
#: 76
msgid ""
"For servers accepting incoming connections, the [link "
"beast.ref.boost__beast__websocket__stream `websocket::stream`] can read the "
"incoming upgrade request and automatically reply. If the handshake meets the "
"requirements, the stream sends back the upgrade response with a [@https://"
"tools.ietf.org/html/rfc6455#section-4.2.2 ['101 Switching Protocols]] status "
"code. If the handshake does not meet the requirements, or falls outside the "
"range of allowed parameters specified by stream options set previously by "
"the caller, the stream sends back an HTTP response with a status code "
"indicating an error. Depending on the keep alive setting, the connection may "
"remain open for a subsequent handshake attempt. A typical HTTP Upgrade "
"response created and sent by the implementation upon receiving an upgrade "
"request handshake will look like this:"
msgstr ""
"对于接受入站连接的服务器，[link beast.ref.boost__beast__websocket__stream "
"`websocket::stream`] 可以读取入站升级请求并自动回复。如果握手满足要求，流会返"
"回一个状态码为 `101 Switching Protocols` 的升级响应。如果握手不符合要求，或超"
"出调用方先前设置的流选项所允许的参数范围，流会返回一个带有错误状态码的 HTTP "
"响应。根据 keep-alive 设置，连接可能会保持打开状态，以便后续再次尝试握手。当"
"接收到升级请求握手时，实现创建并发送的典型 HTTP 升级响应如下所示："

#. type: table title
#: 89
msgid "WebSocket Upgrade HTTP Response"
msgstr "WebSocket 升级 HTTP 响应"

#. type: table cell
#: 89
msgctxt "89"
msgid "Wire Format"
msgstr "线路格式"

#. type: table cell
#: 89
msgctxt "89"
msgid "Description"
msgstr "描述"

#. type: table code
#: 89
msgid ""
"HTTP/1.1 101 Switching Protocols\n"
"Upgrade: websocket\n"
"Connection: upgrade\n"
"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\n"
"Server: Boost.Beast"
msgstr ""
"HTTP/1.1 101 Switching Protocols\n"
"Upgrade: websocket\n"
"Connection: upgrade\n"
"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\n"
"Server: Boost.Beast"

#. type: table cell
#: 89
msgid ""
"The [@https://tools.ietf.org/html/rfc6455#section-11.3.3 ['Sec-WebSocket-"
"Accept]] field value is generated from the request in a fashion specified by "
"the WebSocket protocol."
msgstr ""
"[@https://tools.ietf.org/html/rfc6455#section-11.3.3 `Sec-WebSocket-Accept`] "
"字段值按照 WebSocket 协议规定的方式根据请求生成。"

#. type: paragraph
#: 106
msgid ""
"The [link beast.ref.boost__beast__websocket__stream `stream`] member "
"functions [link beast.ref.boost__beast__websocket__stream.accept `accept`] "
"and [link beast.ref.boost__beast__websocket__stream.async_accept "
"`async_accept`] are used to read the WebSocket HTTP Upgrade request "
"handshake from a stream already connected to an incoming peer, and then send "
"the WebSocket HTTP Upgrade response, as shown:"
msgstr ""
"[link beast.ref.boost__beast__websocket__stream `stream`] 的成员函数 [link "
"beast.ref.boost__beast__websocket__stream.accept `accept`] 和 [link "
"beast.ref.boost__beast__websocket__stream.async_accept `async_accept`] 用于从"
"已连接入站对端的流中读取 WebSocket HTTP 升级请求握手，然后发送 WebSocket "
"HTTP 升级响应，用法如下："

#. type: heading
#: 117
msgid "Handshake Buffering"
msgstr "握手缓冲机制"

#. type: paragraph
#: 119
msgid ""
"It is possible for servers to read data from the stream and decide later "
"that the buffered bytes should be interpreted as a WebSocket upgrade "
"request. To address this usage, overloads of [link "
"beast.ref.boost__beast__websocket__stream.accept `accept`] and [link "
"beast.ref.boost__beast__websocket__stream.async_accept `async_accept`] which "
"accept an additional buffer sequence parameter are provided."
msgstr ""
"服务器可能会先读取流中的数据，稍后才决定将这些已缓冲的字节作为 WebSocket 升级"
"请求来处理。为此，该库提供了 [link "
"beast.ref.boost__beast__websocket__stream.accept `accept`] 和 [link "
"beast.ref.boost__beast__websocket__stream.async_accept `async_accept`] 的重载"
"版本，它们接受一个额外的缓冲区序列参数。"

#. type: paragraph
#: 126
msgid ""
"In this example, the server reads the initial HTTP request header into a "
"dynamic buffer, then later uses the buffered data to attempt a websocket "
"upgrade."
msgstr ""
"在本示例中，服务器先将初始 HTTP 请求头部读入动态缓冲区，随后使用缓冲数据尝试"
"进行 WebSocket 升级。"

#. type: heading
#: 132
msgid "Inspecting HTTP Requests"
msgstr "检查 HTTP 请求内容"

#. type: paragraph
#: 134
msgid ""
"When implementing an HTTP server that also supports WebSocket, the server "
"usually reads the HTTP request from the client. To detect when the incoming "
"HTTP request is a WebSocket Upgrade request, the function [link "
"beast.ref.boost__beast__websocket__is_upgrade `is_upgrade`] may be used."
msgstr ""
"当实现同时支持 WebSocket 的 HTTP 服务器时，服务器通常需要先读取客户端发来的 "
"HTTP 请求。若要判断该请求是否为 WebSocket 升级请求，可以使用 [link "
"beast.ref.boost__beast__websocket__is_upgrade `is_upgrade`] 函数。"

#. type: paragraph
#: 139
msgid ""
"Once the caller determines that the HTTP request is a WebSocket Upgrade, "
"additional overloads of [link "
"beast.ref.boost__beast__websocket__stream.accept `accept`] and [link "
"beast.ref.boost__beast__websocket__stream.async_accept `async_accept`] are "
"provided which receive the entire HTTP request header as an object to "
"perform the handshake. By reading the request manually, the program can "
"handle normal HTTP requests as well as upgrades. The program may also "
"enforce policies based on the HTTP fields, such as Basic Authentication. In "
"this example, the request is first read in using the HTTP algorithms, and "
"then passed to a newly constructed stream:"
msgstr ""
"一旦确认 HTTP 请求是 WebSocket 升级请求，就可以使用 [link "
"beast.ref.boost__beast__websocket__stream.accept `accept`] 和 [link "
"beast.ref.boost__beast__websocket__stream.async_accept `async_accept`] 的额外"
"重载版本，这些重载接受整个 HTTP 请求头部对象来完成握手。通过手动读取请求，程"
"序既能处理普通 HTTP 请求，也能处理升级请求。同时，程序还可以基于 HTTP 字段（"
"例如基本认证）来实施策略控制。以下示例先使用 HTTP 算法读取请求，然后将其传递"
"给新构造的流："

#. type: heading
#: 153
msgid "Subprotocols"
msgstr "子协议"

#. type: paragraph
#: 155
msgid ""
"The WebSocket protocol understands the concept of subprotocols. If the "
"client is requesting one of a set of subprotocols it will set the header "
"[@https://tools.ietf.org/html/rfc6455#section-11.3.4 Sec-WebSocket-Protocol] "
"in the initial WebSocket Upgrade HTTP request. It is up to the server to "
"parse the header and select one of the protocols to accept. The server "
"indicates the selected protocol by setting the [@https://tools.ietf.org/html/"
"rfc6455#section-11.3.4 Sec-WebSocket-Protocol] header in the accept header."
msgstr ""
"WebSocket 协议支持子协议的概念。如果客户端请求使用某个子协议，它会在初始 "
"WebSocket 升级 HTTP 请求中设置 [@https://tools.ietf.org/html/rfc6455#section-"
"11.3.4 Sec-WebSocket-Protocol] 头部。服务器需要解析该头部，并从中选择一个协议"
"接受。服务器通过在响应头部中设置 [@https://tools.ietf.org/html/"
"rfc6455#section-11.3.4 Sec-WebSocket-Protocol] 头部来指示所选协议。"

#. type: paragraph
#: 164
msgid ""
"This is accomplished with a [link "
"beast.ref.boost__beast__websocket__stream_base__decorator `decorator`]."
msgstr ""
"这可以通过 [link beast.ref.boost__beast__websocket__stream_base__decorator "
"`decorator`] 来实现。"

#. type: paragraph
#: 167
msgid ""
"The code that follows demonstrates how a server reads an HTTP request, "
"identifies it as a WebSocket Upgrade, and then checks for a preferred "
"matching subprotocol before performing the WebSocket handshake:"
msgstr ""
"以下代码演示服务器如何读取 HTTP 请求，识别其为 WebSocket 升级请求，并在执行 "
"WebSocket 握手之前检查是否存在匹配的优先子协议："
