Skip to content

Commit 8fc16bd

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

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ 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 {
1818
throw new Error(
19-
"Pass the object returned by require('request') to this function.")
19+
"Pass the object returned by require('request').defaults({}) to this function.")
2020
}
2121

22+
proto = request.Request.prototype
23+
2224
if (!proto._initBeforeDebug) {
2325
proto._initBeforeDebug = proto.init
2426

0 commit comments

Comments
 (0)