diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-11-30 00:53:35 +0300 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-11-30 00:53:35 +0300 |
commit | 6057747e9eda02d5b41385d6555f677314f5780d (patch) | |
tree | cbd3eaeb0701665d1878df84066b2f89679c3db1 /lib/http.js | |
parent | 1db59afb758fa3ad497334ce3f9422269f019d96 (diff) |
Improve HTTP debug messages
Diffstat (limited to 'lib/http.js')
-rw-r--r-- | lib/http.js | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/http.js b/lib/http.js index 7a24f1bbd30..883ab088ca6 100644 --- a/lib/http.js +++ b/lib/http.js @@ -8,7 +8,7 @@ var HTTPParser = process.binding('http_parser').HTTPParser; var debug; var debugLevel = parseInt(process.env.NODE_DEBUG, 16); if (debugLevel & 0x4) { - debug = function (x) { util.error('HTTP: ' + x); }; + debug = function (x) { console.error('HTTP: %s', x); }; } else { debug = function () { }; } @@ -770,7 +770,7 @@ exports.createServer = function (requestListener) { function connectionListener (socket) { var self = this; - debug("new http connection"); + debug("SERVER new http connection"); httpSocketSetup(socket); @@ -790,6 +790,7 @@ function connectionListener (socket) { socket.ondata = function (d, start, end) { var ret = parser.execute(d, start, end - start); if (ret instanceof Error) { + debug("parse error"); socket.destroy(ret); } else if (parser.incoming && parser.incoming.upgrade) { var bytesParsed = ret; @@ -906,26 +907,26 @@ function Client ( ) { }; self.addListener("connect", function () { - debug('client connected'); + debug('CLIENT connected'); self.ondata = onData; self.onend = onEnd; self._initParser(); - debug('requests: ' + util.inspect(self._outgoing)); + debug('CLIENT requests: ' + util.inspect(self._outgoing.map(function (r) { return r.method; }))); outgoingFlush(self); }); function onEnd() { if (self.parser) self.parser.finish(); - debug("self got end closing. readyState = " + self.readyState); + debug("CLIENT got end closing. readyState = " + self.readyState); self.end(); }; self.addListener("close", function (e) { if (e) return; - debug("HTTP CLIENT onClose. readyState = " + self.readyState); + debug("CLIENT onClose. readyState = " + self.readyState); // finally done with the request self._outgoing.shift(); @@ -961,14 +962,14 @@ Client.prototype._initParser = function () { self.parser.reinitialize('response'); self.parser.socket = self; self.parser.onIncoming = function (res) { - debug("incoming response!"); + debug("CLIENT incoming response!"); var req = self._outgoing[0]; // Responses to HEAD requests are AWFUL. Ask Ryan. // A major oversight in HTTP. Hence this nastiness. var isHeadResponse = req.method == "HEAD"; - debug('isHeadResponse ' + isHeadResponse); + debug('CLIENT isHeadResponse ' + isHeadResponse); if (res.statusCode == 100) { // restart the parser, as this is a continue message. @@ -981,7 +982,7 @@ Client.prototype._initParser = function () { } res.addListener('end', function ( ) { - debug("request complete disconnecting. readyState = " + self.readyState); + debug("CLIENT request complete disconnecting. readyState = " + self.readyState); // For the moment we reconnect for every request. FIXME! // All that should be required for keep-alive is to not reconnect, // but outgoingFlush instead. @@ -1020,7 +1021,7 @@ Client.prototype._onOutgoingSent = function (message) { // Instead, we just check if the connection is closed, and if so // reconnect if we have pending messages. if (this._outgoing.length && this.readyState == "closed") { - debug("HTTP client request flush. reconnect. readyState = " + this.readyState); + debug("CLIENT request flush. reconnect. readyState = " + this.readyState); this._reconnect(); } }; @@ -1028,7 +1029,7 @@ Client.prototype._onOutgoingSent = function (message) { Client.prototype._reconnect = function () { if (this.readyState === "closed") { - debug("HTTP CLIENT: reconnecting readyState = " + this.readyState); + debug("CLIENT reconnecting readyState = " + this.readyState); this.connect(this.port, this.host); } }; |