事件:'connection'
【Event: 'connection'】
socket<stream.Duplex>
当建立新的 TCP 流时,会触发此事件。socket 通常是 net.Socket 类型的对象。通常用户不需要访问此事件。特别是,由于协议解析器附加到套接字的方式,套接字不会触发 'readable' 事件。socket 也可以通过 request.socket 访问。
【This event is emitted when a new TCP stream is established. socket is
typically an object of type net.Socket. Usually users will not want to
access this event. In particular, the socket will not emit 'readable' events
because of how the protocol parser attaches to the socket. The socket can
also be accessed at request.socket.】
此事件也可以由用户显式触发,以向 HTTP 服务器注入连接。在这种情况下,可以传递任何 Duplex 流。
【This event can also be explicitly emitted by users to inject connections
into the HTTP server. In that case, any Duplex stream can be passed.】
如果在这里调用 socket.setTimeout(),当套接字处理完请求后,超时时间将被替换为 server.keepAliveTimeout(如果 server.keepAliveTimeout 非零)。
【If socket.setTimeout() is called here, the timeout will be replaced with
server.keepAliveTimeout when the socket has served a request (if
server.keepAliveTimeout is non-zero).】
此事件保证会传递一个 <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>.】