Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ Server.prototype.handleUpgrade = function (req, socket, upgradeHead) {

var self = this;
this.verify(req, true, function (err, success) {
if (err) {
socket.end();
if (!success) {
abortConnection(socket, err);
return;
}

Expand Down Expand Up @@ -463,3 +463,27 @@ Server.prototype.attach = function (server, options) {
});
}
};

/**
* Closes the connection
*
* @param {net.Socket} socket
* @param {code} error code
* @api private
*/

function abortConnection (socket, code) {
if (socket.writable) {
var message = Server.errorMessages.hasOwnProperty(code) ? Server.errorMessages[code] : code;
var length = Buffer.byteLength(message);
socket.write(
'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.destroy();
}