* Close the WebSocket connection * * @param {net.Socket} socket * @param {string} errorCode - the error code * @param {object} errorContext - additional error context
(
socket,
errorCode,
errorContext: { message?: string } = {},
)
| 1044 | */ |
| 1045 | |
| 1046 | function abortUpgrade( |
| 1047 | socket, |
| 1048 | errorCode, |
| 1049 | errorContext: { message?: string } = {}, |
| 1050 | ) { |
| 1051 | socket.on("error", () => { |
| 1052 | debug("ignoring error from closed connection"); |
| 1053 | }); |
| 1054 | if (socket.writable) { |
| 1055 | const message = errorContext.message || Server.errorMessages[errorCode]; |
| 1056 | const length = Buffer.byteLength(message); |
| 1057 | socket.write( |
| 1058 | "HTTP/1.1 400 Bad Request\r\n" + |
| 1059 | "Connection: close\r\n" + |
| 1060 | "Content-type: text/html\r\n" + |
| 1061 | "Content-Length: " + |
| 1062 | length + |
| 1063 | "\r\n" + |
| 1064 | "\r\n" + |
| 1065 | message, |
| 1066 | ); |
| 1067 | } |
| 1068 | socket.destroy(); |
| 1069 | } |
| 1070 | |
| 1071 | /* eslint-disable */ |
| 1072 |