Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback option #2169

Merged
merged 1 commit into from Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})