事件:'upgrade'


【Event: 'upgrade'

每当客户端的 HTTP 升级请求被接受时就会触发。默认情况下,所有 HTTP 升级请求都会被忽略(即只会触发常规的 'request' 事件,遵循正常的 HTTP 请求/响应流程),除非你监听此事件,在这种情况下它们都会被接受(即会触发 'upgrade' 事件,并且未来的通信必须直接通过原始套接字处理)。你可以通过使用服务器的 shouldUpgradeCallback 选项来更精确地控制这一点。

【Emitted each time a client's HTTP upgrade request is accepted. By default all HTTP upgrade requests are ignored (i.e. only regular 'request' events are emitted, sticking with the normal HTTP request/response flow) unless you listen to this event, in which case they are all accepted (i.e. the 'upgrade' event is emitted instead, and future communication must handled directly through the raw socket). You can control this more precisely by using the server shouldUpgradeCallback option.】

参加此活动是可选的,客户不能要求更改协议。

【Listening to this event is optional and clients cannot insist on a protocol change.】

在此事件被触发后,请求的套接字将不会有 'data' 事件监听器,这意味着需要绑定监听器才能处理发送到该套接字的服务器数据。

【After this event is emitted, the request's socket will not have a 'data' event listener, meaning it will need to be bound in order to handle data sent to the server on that socket.】

如果 shouldUpgradeCallback 接受了升级,但没有注册事件处理程序,则套接字将被销毁,从而导致客户端的连接立即关闭。

【If an upgrade is accepted by shouldUpgradeCallback but no event handler is registered then the socket is destroyed, resulting in an immediate connection closure for the client.】

此事件保证会传递一个 <net.Socket> 类的实例,该类是 <stream.Duplex> 的子类,除非用户指定了其他类型的套接字而不是 <net.Socket>

【This event is guaranteed to be passed an instance of the <net.Socket> class, a subclass of <stream.Duplex>, unless the user specifies a socket type other than <net.Socket>.】