From c1448951334c7cfc5f1d1fff83c35117b6cf729f Mon Sep 17 00:00:00 2001 From: Brian Kopp Date: Fri, 13 Sep 2019 03:21:37 -0600 Subject: [PATCH] [feat] add additional debug messages (#586) These additional messages will help more quickly diagnose the reason for error messages. --- lib/server.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/server.js b/lib/server.js index df4058ea57..2d9a45c7a8 100644 --- a/lib/server.js +++ b/lib/server.js @@ -148,6 +148,7 @@ Server.prototype.verify = function (req, upgrade, fn) { var isOriginInvalid = checkInvalidHeaderChar(req.headers.origin); if (isOriginInvalid) { req.headers.origin = null; + debug('origin header invalid'); return fn(Server.errors.BAD_REQUEST, false); } @@ -155,6 +156,7 @@ Server.prototype.verify = function (req, upgrade, fn) { var sid = req._query.sid; if (sid) { if (!this.clients.hasOwnProperty(sid)) { + debug('unknown sid "%s"', sid); return fn(Server.errors.UNKNOWN_SID, false); } if (!upgrade && this.clients[sid].transport.name !== transport) { @@ -309,6 +311,7 @@ Server.prototype.handshake = function (transportName, req) { transport.supportsBinary = true; } } catch (e) { + debug('error handshaking to transport "%s"', transportName); sendErrorMessage(req, req.res, Server.errors.BAD_REQUEST); return; } @@ -552,23 +555,33 @@ function checkInvalidHeaderChar(val) { val += ''; if (val.length < 1) return false; - if (!validHdrChars[val.charCodeAt(0)]) + if (!validHdrChars[val.charCodeAt(0)]) { + debug('invalid header, index 0, char "%s"', val.charCodeAt(0)); return true; + } if (val.length < 2) return false; - if (!validHdrChars[val.charCodeAt(1)]) + if (!validHdrChars[val.charCodeAt(1)]) { + debug('invalid header, index 1, char "%s"', val.charCodeAt(1)); return true; + } if (val.length < 3) return false; - if (!validHdrChars[val.charCodeAt(2)]) + if (!validHdrChars[val.charCodeAt(2)]) { + debug('invalid header, index 2, char "%s"', val.charCodeAt(2)); return true; + } if (val.length < 4) return false; - if (!validHdrChars[val.charCodeAt(3)]) + if (!validHdrChars[val.charCodeAt(3)]) { + debug('invalid header, index 3, char "%s"', val.charCodeAt(3)); return true; + } for (var i = 4; i < val.length; ++i) { - if (!validHdrChars[val.charCodeAt(i)]) + if (!validHdrChars[val.charCodeAt(i)]) { + debug('invalid header, index "%i", char "%s"', i, val.charCodeAt(i)); return true; + } } return false; }