事件:'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 扩展或发送不包含 HTTP/2 (h2) 的 ALPN 扩展,则会触发此事件。较新版本的 Node.js 仅在 allowHTTP1false 且客户端未发送 ALPN 扩展时才会触发此事件。如果客户端发送不包含 HTTP/2(或 HTTP/1.1,如果 allowHTTP1true)的 ALPN 扩展,则 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.