MCPcopy
hub / github.com/socketio/socket.io / abortUpgrade

Function abortUpgrade

packages/engine.io/lib/server.ts:1046–1069  ·  view source on GitHub ↗

* 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 } = {},
)

Source from the content-addressed store, hash-verified

1044 */
1045
1046function 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

Callers 2

callbackMethod · 0.85
closeConnectionMethod · 0.85

Calls 4

debugFunction · 0.85
onMethod · 0.45
writeMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected