abortConnection static method

void abortConnection(
  1. SocketConnect connect,
  2. dynamic code
)

Implementation

static void abortConnection(SocketConnect connect, code) {
  var socket = connect.websocket;
  if (socket?.readyState == HttpStatus.ok) {
    var message = serverErrorMessages.containsKey(code)
        ? serverErrorMessages[code]
        : code;

    var length = utf8.encode(message).length;
    socket!.add('HTTP/1.1 400 Bad Request\r\n'
            'Connection: close\r\n'
            'Content-type: text/html\r\n'
            'Content-Length: $length\r\n'
            '\r\n' +
        message);
  }
  socket?.close();
}