Skip to content

Commit

Permalink
make request.defaults(options, requester) run the requester for all m…
Browse files Browse the repository at this point in the history
…ethods

It wasn't working on PUT and POST before.
  • Loading branch information
Chris Anderson committed Dec 5, 2013
1 parent cdb075f commit 0ec8209
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ request.defaults = function (options, requester) {
return de
}

function requester(params) {
if(typeof params.options._requester === 'function') {
return params.options._requester
} else {
return request
}
}

request.forever = function (agentOptions, optionsArg) {
var options = {}
if (optionsArg) {
Expand All @@ -109,17 +117,17 @@ request.get = request
request.post = function (uri, options, callback) {
var params = initParams(uri, options, callback)
params.options.method = 'POST'
return request(params.uri || null, params.options, params.callback)
return requester(params)(params.uri || null, params.options, params.callback)
}
request.put = function (uri, options, callback) {
var params = initParams(uri, options, callback)
params.options.method = 'PUT'
return request(params.uri || null, params.options, params.callback)
return requester(params)(params.uri || null, params.options, params.callback)
}
request.patch = function (uri, options, callback) {
var params = initParams(uri, options, callback)
params.options.method = 'PATCH'
return request(params.uri || null, params.options, params.callback)
return requester(params)(params.uri || null, params.options, params.callback)
}
request.head = function (uri, options, callback) {
var params = initParams(uri, options, callback)
Expand All @@ -130,15 +138,13 @@ request.head = function (uri, options, callback) {
params.options.multipart) {
throw new Error("HTTP HEAD requests MUST NOT include a request body.")
}
return request(params.uri || null, params.options, params.callback)

return requester(params)(params.uri || null, params.options, params.callback)
}
request.del = function (uri, options, callback) {
var params = initParams(uri, options, callback)
params.options.method = 'DELETE'
if(typeof params.options._requester === 'function') {
request = params.options._requester
}
return request(params.uri || null, params.options, params.callback)
return requester(params)(params.uri || null, params.options, params.callback)
}
request.jar = function () {
return new CookieJar
Expand Down

0 comments on commit 0ec8209

Please sign in to comment.