Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
language: node_js

node_js:
- "0.11"
- "iojs"
- "0.12"
- "0.10"
- "0.8"

env:
- REQUEST_VERSION=2.30.0
- REQUEST_VERSION=2.34.0
- REQUEST_VERSION=2.40.0
- REQUEST_VERSION=2.41.0
- REQUEST_VERSION=2.42.0
- REQUEST_VERSION=2.43.0
- REQUEST_VERSION=2.44.0
- REQUEST_VERSION=2.45.0
- REQUEST_VERSION=2.50.0
- REQUEST_VERSION=2.52.0
- REQUEST_VERSION=2.53.0
- REQUEST_VERSION=2.54.0
- REQUEST_VERSION=2.55.0

before_script:
- rm -r node_modules/request/
Expand Down
150 changes: 75 additions & 75 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
var clone = require('clone');
var clone = require('clone')

var debugId = 0;
var debugId = 0

module.exports = exports = function(request, log) {
log = log || exports.log;
log = log || exports.log

var proto;
if (request.Request) {
proto = request.Request.prototype;
} else if (request.get && request.post) {
// The object returned by request.defaults() doesn't include the
// Request property, so do this horrible thing to get at it. Per
// Wikipedia, port 4 is unassigned.
var req = request('http://localhost:4').on('error', function() { });
proto = req.constructor.prototype;
} else {
throw new Error(
"Pass the object returned by require('request') to this function.");
}
var proto
if (request.Request) {
proto = request.Request.prototype
} else if (request.get && request.post) {
// The object returned by request.defaults() doesn't include the
// Request property, so do this horrible thing to get at it. Per
// Wikipedia, port 4 is unassigned.
var req = request('http://localhost:4').on('error', function() { })
proto = req.constructor.prototype
} else {
throw new Error(
"Pass the object returned by require('request') to this function.")
}

if (!proto._initBeforeDebug) {
proto._initBeforeDebug = proto.init;
if (!proto._initBeforeDebug) {
proto._initBeforeDebug = proto.init

proto.init = function() {
if (!this._debugId) {
proto.init = function() {
if (!this._debugId) {

this.on('request', function(req) {
var data = {
debugId : this._debugId,
uri : this.uri.href,
method : this.method,
headers : clone(this.headers)
};
if (this.body) {
data.body = this.body.toString('utf8');
}
log('request', data, this);
this.on('request', function(req) {
var data = {
debugId : this._debugId,
uri : this.uri.href,
method : this.method,
headers : clone(this.headers)
}
if (this.body) {
data.body = this.body.toString('utf8')
}
log('request', data, this)

}).on('response', function(res) {
if (this.callback) {
// callback specified, request will buffer the body for
// us, so wait until the complete event to do anything
} else {
// cannot get body since no callback specified
log('response', {
debugId : this._debugId,
headers : clone(res.headers),
statusCode : res.statusCode
}, this);
}
}).on('response', function(res) {
if (this.callback) {
// callback specified, request will buffer the body for
// us, so wait until the complete event to do anything
} else {
// cannot get body since no callback specified
log('response', {
debugId : this._debugId,
headers : clone(res.headers),
statusCode : res.statusCode
}, this)
}

}).on('complete', function(res, body) {
if (this.callback) {
log('response', {
debugId : this._debugId,
headers : clone(res.headers),
statusCode : res.statusCode,
body : res.body
}, this);
}
}).on('complete', function(res, body) {
if (this.callback) {
log('response', {
debugId : this._debugId,
headers : clone(res.headers),
statusCode : res.statusCode,
body : res.body
}, this)
}

}).on('redirect', function() {
var type = (this.response.statusCode == 401 ? 'auth' : 'redirect');
log(type, {
debugId : this._debugId,
statusCode : this.response.statusCode,
headers : clone(this.response.headers),
uri : this.uri.href
}, this);
});
}).on('redirect', function() {
var type = (this.response.statusCode == 401 ? 'auth' : 'redirect')
log(type, {
debugId : this._debugId,
statusCode : this.response.statusCode,
headers : clone(this.response.headers),
uri : this.uri.href
}, this)
})

this._debugId = ++debugId;
}
this._debugId = ++debugId
}

return proto._initBeforeDebug.apply(this, arguments);
};
return proto._initBeforeDebug.apply(this, arguments)
}
}

if (!request.stopDebugging) {
request.stopDebugging = function() {
proto.init = proto._initBeforeDebug;
delete proto._initBeforeDebug;
};
if (!request.stopDebugging) {
request.stopDebugging = function() {
proto.init = proto._initBeforeDebug
delete proto._initBeforeDebug
}
};
}
}

exports.log = function(type, data, r) {
var toLog = {};
toLog[type] = data;
console.error(toLog);
};
var toLog = {}
toLog[type] = data
console.error(toLog)
}
69 changes: 35 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
{
"name" : "request-debug",
"author" : "James Nylen <jnylen@gmail.com>",
"description" : "Library to assist with debugging HTTP(s) requests made by the request module.",
"version" : "0.1.1",
"repository" : {
"type" : "git",
"url" : "https://github.com/request/request-debug"
},
"bugs" : {
"url" : "https://github.com/request/request-debug/issues"
},
"license" : "MIT",
"keywords" : [
"request",
"debug",
"http",
"https",
"headers"
],
"scripts" : {
"test" : "node node_modules/.bin/mocha"
},
"main" : "index.js",
"devDependencies" : {
"express" : "~4.8.6",
"mocha" : "~1.21.4",
"passport" : "~0.2.0",
"passport-http" : "~0.2.2",
"request" : "~2.40.0",
"should" : "~4.0.4"
},
"dependencies" : {
"clone" : "~0.1.18"
}
"name" : "request-debug",
"author" : "James Nylen <jnylen@gmail.com>",
"description" : "Library to assist with debugging HTTP(s) requests made by the request module.",
"version" : "0.1.1",
"repository" : {
"type" : "git",
"url" : "https://github.com/request/request-debug"
},
"bugs" : {
"url" : "https://github.com/request/request-debug/issues"
},
"license" : "MIT",
"keywords" : [
"request",
"debug",
"http",
"https",
"headers"
],
"scripts" : {
"test" : "node node_modules/.bin/mocha"
},
"main" : "index.js",
"devDependencies" : {
"detect-engine" : "~1.0.2",
"express" : "~4.8.6",
"mocha" : "~1.21.4",
"passport" : "~0.2.0",
"passport-http" : "~0.2.2",
"request" : "~2.50.0",
"should" : "~4.0.4"
},
"dependencies" : {
"clone" : "~0.1.18"
}
}
Loading