Skip to content

Commit

Permalink
Allow static invoking of convenience methods
Browse files Browse the repository at this point in the history
  • Loading branch information
simov committed Mar 27, 2015
1 parent 5b03774 commit c43477e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -61,7 +61,7 @@ verbs.forEach(function(verb){
request[verb] = function(uri, options, callback){
var params = initParams(uri, options, callback)
params.options.method = method
return this(params.uri || null, params.options, params.callback)
return (this || request)(params.uri || null, params.options, params.callback)
}
})

Expand Down
15 changes: 15 additions & 0 deletions tests/test-defaults.js
Expand Up @@ -105,6 +105,11 @@ tape('setup', function(t) {
})
})

s.on('/function', function(req, resp) {
resp.writeHead(200, {'Content-Type': 'text/plain'})
resp.end()
})

t.end()
})
})
Expand Down Expand Up @@ -299,6 +304,16 @@ tape('test only setting undefined properties', function(t) {
})
})

tape('test only function', function(t) {
var post = request.post
t.doesNotThrow(function () {
post(s.url + '/function', function (e, r, b) {
t.equal(r.statusCode, 200)
t.end()
})
})
})

tape('cleanup', function(t) {
s.close(function() {
t.end()
Expand Down

2 comments on commit c43477e

@rehia
Copy link

@rehia rehia commented on c43477e Apr 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix an issue which exists in 2.54, and makes request.post to throw an error.
It would be great to have a 2.54.n to fix this.
Actually, I need to go back to 2.53

@simov
Copy link
Member Author

@simov simov commented on c43477e Apr 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rehia the new release with this fix is coming soon.

Please sign in to comment.