Skip to content

Commit

Permalink
Merge pull request #2169 from simov/callback-option
Browse files Browse the repository at this point in the history
Add callback option
  • Loading branch information
simov committed Apr 15, 2016
2 parents 8f2a142 + 6c32bf4 commit 5a8ddc8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -814,6 +814,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]).

- `time` - If `true`, the request-response cycle (including all redirects) is timed at millisecond resolution, and the result provided on the response's `elapsedTime` property.
- `har` - A [HAR 1.2 Request Object](http://www.softwareishard.com/blog/har-12-spec/#request), will be processed from HAR format into options overwriting matching values *(see the [HAR 1.2 section](#support-for-har-1.2) for details)*
- `callback` - alternatively pass the request's callback in the options object

The callback argument gets 3 arguments:

Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -37,7 +37,7 @@ function initParams(uri, options, callback) {
extend(params, uri)
}

params.callback = callback
params.callback = callback || params.callback
return params
}

Expand Down
30 changes: 30 additions & 0 deletions tests/test-api.js
@@ -0,0 +1,30 @@
'use strict'

var http = require('http')
, request = require('../index')
, tape = require('tape')
, server


tape('setup', function (t) {
server = http.createServer()
server.on('request', function (req, res) {
res.writeHead(202)
req.pipe(res)
})
server.listen(6767, t.end)
})

tape('callback option', function (t) {
request({
url: 'http://localhost:6767',
callback: function (err, res, body) {
t.equal(res.statusCode, 202)
t.end()
}
})
})

tape('cleanup', function(t) {
server.close(t.end)
})

0 comments on commit 5a8ddc8

Please sign in to comment.