Skip to content

Commit 45187a2

Browse files
author
Pedro Branco
committed
Fix changing request by reference
1 parent 54a0fea commit 45187a2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ module.exports = exports = function(request, log) {
66
log = log || exports.log
77

88
var proto
9-
if (request.Request) {
10-
proto = request.Request.prototype
11-
} else if (request.get && request.post) {
9+
10+
if (!request.Request && request.get && request.post) {
1211
// The object returned by request.defaults() doesn't include the
1312
// Request property, so do this horrible thing to get at it. Per
1413
// Wikipedia, port 4 is unassigned.
15-
var req = request('http://localhost:4').on('error', function() { })
16-
proto = req.constructor.prototype
14+
var Request = request('http://localhost:4').on('error', function() { })
15+
request.Request = Object.assign({}, Request);
16+
request.Request.prototype = Object.assign({}, Request.prototype);
1717
} else {
18+
console.log(request);
1819
throw new Error(
19-
"Pass the object returned by require('request') to this function.")
20+
"Pass the object returned by require('request').defaults({}) to this function.")
2021
}
2122

23+
proto = request.Request.prototype
24+
2225
if (!proto._initBeforeDebug) {
2326
proto._initBeforeDebug = proto.init
2427

0 commit comments

Comments
 (0)