Skip to content

Commit

Permalink
Merge branch 'master' into greenkeeper-karma-tap-3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
simov committed Aug 28, 2016
2 parents 62712d4 + bfb3a46 commit 6b24418
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -811,7 +811,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.
- `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. The `responseStartTime` property is also available to indicate the timestamp when the response begins.
- `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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -29,7 +29,7 @@
"combined-stream": "~1.0.5",
"extend": "~3.0.0",
"forever-agent": "~0.6.1",
"form-data": "~1.0.0-rc4",
"form-data": "~1.0.1",
"har-validator": "~2.0.6",
"hawk": "~3.1.3",
"http-signature": "~1.1.0",
Expand Down
4 changes: 4 additions & 0 deletions request.js
Expand Up @@ -958,6 +958,10 @@ Request.prototype.onRequestResponse = function (response) {
})

responseContent.on('data', function (chunk) {
if (self.timing && !self.responseStarted) {
self.responseStartTime = (new Date()).getTime()
response.responseStartTime = self.responseStartTime
}
self._destdata = true
self.emit('data', chunk)
})
Expand Down
4 changes: 2 additions & 2 deletions tests/test-form-data-error.js
Expand Up @@ -75,12 +75,12 @@ tape('form-data should throw on null value', function (t) {
key: null
}
})
}, /Cannot read property 'path' of null/)
}, TypeError)
t.end()
})

tape('cleanup', function(t) {
s.close(function() {
t.end()
})
})
})
9 changes: 7 additions & 2 deletions tests/test-timing.js
Expand Up @@ -27,21 +27,26 @@ tape('setup', function(t) {

tape('non-redirected request is timed', function(t) {
var options = {time: true}
request('http://localhost:' + plain_server.port + '/', options, function(err, res, body) {
var r = request('http://localhost:' + plain_server.port + '/', options, function(err, res, body) {
t.equal(err, null)
t.equal(typeof res.elapsedTime, 'number')
t.equal(typeof res.responseStartTime, 'number')
t.equal((res.elapsedTime > 0), true)
t.equal((res.responseStartTime > r.startTime), true)
t.end()
})
})

tape('redirected request is timed with rollup', function(t) {
var options = {time: true}
request('http://localhost:' + plain_server.port + '/redir', options, function(err, res, body) {
var r = request('http://localhost:' + plain_server.port + '/redir', options, function(err, res, body) {
t.equal(err, null)
t.equal(typeof res.elapsedTime, 'number')
t.equal(typeof res.responseStartTime, 'number')
t.equal((res.elapsedTime > 0), true)
t.equal((res.responseStartTime > 0), true)
t.equal((res.elapsedTime > redirect_mock_time), true)
t.equal((res.responseStartTime > r.startTime), true)
t.end()
})
})
Expand Down

0 comments on commit 6b24418

Please sign in to comment.