diff --git a/lib/server.js b/lib/server.js index d52120a58..76df2ef45 100644 --- a/lib/server.js +++ b/lib/server.js @@ -266,11 +266,13 @@ function sendErrorMessage (req, res, code) { } else { headers['Access-Control-Allow-Origin'] = '*'; } - res.writeHead(400, headers); - res.end(JSON.stringify({ - code: code, - message: Server.errorMessages[code] - })); + if (res !== undefined) { + res.writeHead(400, headers); + res.end(JSON.stringify({ + code: code, + message: Server.errorMessages[code] + })); + } } /** @@ -379,7 +381,7 @@ Server.prototype.handleUpgrade = function (req, socket, upgradeHead) { Server.prototype.onWebSocket = function (req, socket) { socket.on('error', onUpgradeError); - if (!transports[req._query.transport].prototype.handlesUpgrades) { + if (transports[req._query.transport] !== undefined && !transports[req._query.transport].prototype.handlesUpgrades) { debug('transport doesnt handle upgraded requests'); socket.close(); return;