Skip to content

Commit

Permalink
Added results.statusCode
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbankhead committed Feb 7, 2017
1 parent 140be40 commit 39f5160
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@
const userAgent = results.requestOptionsFinal.headers['user-agent']
```

- `statusCode` INTEGER
- The final status code of the request
- Example:
```js
const statusCode = results.statusCode
// > 200, 206, 404, etc.
```

- `time` OBJECT
- `response` INTEGER
- the time it took to download and process the response, in milliseconds
Expand Down
2 changes: 2 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function httpRequest (givenURL, options, callback, currentRedirects) {
redirects: 0,
responseHeaders: null,
requestOptionsFinal: null,
statusCode: NaN,
time: null,
url: null
}
Expand Down Expand Up @@ -259,6 +260,7 @@ function httpRequest (givenURL, options, callback, currentRedirects) {
response: Date.now() - startResponseTime
}
results.data = Buffer.concat(dataRecieved, results.dataLength)
results.statusCode = response.statusCode

if (response.statusCode > 299 && response.headers.location && results.options.redirectLimit > results.redirects && results.error === null) {
dataRecieved = []
Expand Down

0 comments on commit 39f5160

Please sign in to comment.