Skip to content

Commit c144895

Browse files
BrianKoppdarrachequesne
authored andcommitted
[feat] add additional debug messages (#586)
These additional messages will help more quickly diagnose the reason for error messages.
1 parent a967626 commit c144895

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lib/server.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@ Server.prototype.verify = function (req, upgrade, fn) {
148148
var isOriginInvalid = checkInvalidHeaderChar(req.headers.origin);
149149
if (isOriginInvalid) {
150150
req.headers.origin = null;
151+
debug('origin header invalid');
151152
return fn(Server.errors.BAD_REQUEST, false);
152153
}
153154

154155
// sid check
155156
var sid = req._query.sid;
156157
if (sid) {
157158
if (!this.clients.hasOwnProperty(sid)) {
159+
debug('unknown sid "%s"', sid);
158160
return fn(Server.errors.UNKNOWN_SID, false);
159161
}
160162
if (!upgrade && this.clients[sid].transport.name !== transport) {
@@ -309,6 +311,7 @@ Server.prototype.handshake = function (transportName, req) {
309311
transport.supportsBinary = true;
310312
}
311313
} catch (e) {
314+
debug('error handshaking to transport "%s"', transportName);
312315
sendErrorMessage(req, req.res, Server.errors.BAD_REQUEST);
313316
return;
314317
}
@@ -552,23 +555,33 @@ function checkInvalidHeaderChar(val) {
552555
val += '';
553556
if (val.length < 1)
554557
return false;
555-
if (!validHdrChars[val.charCodeAt(0)])
558+
if (!validHdrChars[val.charCodeAt(0)]) {
559+
debug('invalid header, index 0, char "%s"', val.charCodeAt(0));
556560
return true;
561+
}
557562
if (val.length < 2)
558563
return false;
559-
if (!validHdrChars[val.charCodeAt(1)])
564+
if (!validHdrChars[val.charCodeAt(1)]) {
565+
debug('invalid header, index 1, char "%s"', val.charCodeAt(1));
560566
return true;
567+
}
561568
if (val.length < 3)
562569
return false;
563-
if (!validHdrChars[val.charCodeAt(2)])
570+
if (!validHdrChars[val.charCodeAt(2)]) {
571+
debug('invalid header, index 2, char "%s"', val.charCodeAt(2));
564572
return true;
573+
}
565574
if (val.length < 4)
566575
return false;
567-
if (!validHdrChars[val.charCodeAt(3)])
576+
if (!validHdrChars[val.charCodeAt(3)]) {
577+
debug('invalid header, index 3, char "%s"', val.charCodeAt(3));
568578
return true;
579+
}
569580
for (var i = 4; i < val.length; ++i) {
570-
if (!validHdrChars[val.charCodeAt(i)])
581+
if (!validHdrChars[val.charCodeAt(i)]) {
582+
debug('invalid header, index "%i", char "%s"', i, val.charCodeAt(i));
571583
return true;
584+
}
572585
}
573586
return false;
574587
}

0 commit comments

Comments
 (0)