Skip to content

Commit

Permalink
Merge pull request request#727 from jchris/patch-1
Browse files Browse the repository at this point in the history
fix requester bug
  • Loading branch information
mikeal committed Dec 5, 2013
2 parents cdb075f + 0ec8209 commit 04e2d26
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 04e2d26

Please sign in to comment.