lib/websocket-server.js
function abortHandshake(socket, code, message, headers) {
  if (socket.writable) {
    message = message || STATUS_CODES[code];
    headers = {
      Connection: 'close',
      'Content-type': 'text/html',
      'Content-Length': Buffer.byteLength(message),
      ...headers
    };

    socket.write(
      `HTTP/1.1 ${code} ${STATUS_CODES[code]}\r\n` +
        Object.keys(headers)
          .map((h) => `${h}: ${headers[h]}`)
          .join('\r\n') +
        '\r\n\r\n' +
        message
    );
  }

  socket.removeListener('error', socketOnError);
  socket.destroy();
}
function abortHandshake(socket, code, message, headers) {
  if (socket.writable) {
    message = message || STATUS_CODES[code];
    headers = {
      Connection: 'close',
      'Content-type': 'text/html',
      'Content-Length': Buffer.byteLength(message),
      ...headers
    };

    socket.write(
      `HTTP/1.1 ${code} ${STATUS_CODES[code]}\r\n` +
        Object.keys(headers)
          .map((h) => `${h}: ${headers[h]}`)
          .join('\r\n') +
        '\r\n\r\n' +
        message
    );
  }

  socket.removeListener('error', socketOnError);
  socket.destroy();
}
function abortHandshake ( socket , code , message , headers ) { if ( socket . writable ) { message = message || STATUS_CODES [ code ] ; headers = { Connection : 'close' , 'Content-type' : 'text/html' , 'Content-Length' : Buffer . byteLength ( message ) , ... headers } ; socket . write ( ` ${ code } ${ STATUS_CODES [ code ] } \r \n ` + Object . keys ( headers ) . map ( ( h ) => ` ${ h } ${ headers [ h ] } ` ) . join ( '\r\n' ) + '\r\n\r\n' + message ) ; } socket . removeListener ( 'error' , socketOnError ) ; socket . destroy ( ) ; }
Close the connection when preconditions are not fulfilled.

@param {net.Socket} socket The socket of the upgrade request
@param {Number} code The HTTP response status code
@param {String} [message] The HTTP response body
@param {Object} [headers] Additional HTTP response headers
@private
Close the connection when preconditions are not fulfilled .