事件:'upgrade'


¥Event: 'upgrade'

每次客户端的 HTTP 升级请求被接受时都会发出。默认情况下,所有 HTTP 升级请求都会被忽略(即,仅发出常规的 'request' 事件,遵循正常的 HTTP 请求/响应流程),除非你监听此事件。在这种情况下,所有 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> 以外的套接字类型,否则此事件保证传入 <net.Socket> 类(<stream.Duplex> 的子类)的实例。

¥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>.