事件:'unknownProtocol'


【Event: 'unknownProtocol'

当连接的客户端无法协商允许使用的协议(即 HTTP/2 或 HTTP/1.1)时,会触发 'unknownProtocol' 事件。事件处理程序会接收用于处理的套接字。如果未为此事件注册监听器,则连接将被终止。可以使用传递给 http2.createSecureServer()'unknownProtocolTimeout' 选项指定超时时间。

【The 'unknownProtocol' event is emitted when a connecting client fails to negotiate an allowed protocol (i.e. HTTP/2 or HTTP/1.1). The event handler receives the socket for handling. If no listener is registered for this event, the connection is terminated. A timeout may be specified using the 'unknownProtocolTimeout' option passed to http2.createSecureServer().】

在较早版本的 Node.js 中,如果 allowHTTP1false,并且在 TLS 握手过程中,客户端要么未发送 ALPN 扩展,要么发送的 ALPN 扩展不包含 HTTP/2(h2),则会触发此事件。Node.js 的新版本仅在 allowHTTP1false 且客户端未发送 ALPN 扩展时才会触发此事件。如果客户端发送的 ALPN 扩展不包含 HTTP/2(或如果 allowHTTP1true,则不包含 HTTP/1.1),TLS 握手将会失败,并且不会建立安全连接。

【In earlier versions of Node.js, this event would be emitted if allowHTTP1 is false and, during the TLS handshake, the client either does not send an ALPN extension or sends an ALPN extension that does not include HTTP/2 (h2). Newer versions of Node.js only emit this event if allowHTTP1 is false and the client does not send an ALPN extension. If the client sends an ALPN extension that does not include HTTP/2 (or HTTP/1.1 if allowHTTP1 is true), the TLS handshake will fail and no secure connection will be established.】

兼容性接口

【See the Compatibility API.】