Skip to content

Commit

Permalink
Provide timings
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Aug 25, 2018
1 parent dda1ce9 commit deeb0b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
],
"dependencies": {
"@sindresorhus/is": "^0.11.0",
"@szmarczak/http-timer": "^1.0.2",
"cacheable-request": "^4.0.1",
"decompress-response": "^3.3.0",
"duplexer3": "^0.1.4",
Expand Down
7 changes: 6 additions & 1 deletion source/request-as-event-emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const https = require('https');
const urlLib = require('url');
const CacheableRequest = require('cacheable-request');
const is = require('@sindresorhus/is');
const timer = require('@szmarczak/http-timer');
const timedOut = require('./timed-out');
const getBodySize = require('./get-body-size');
const getResponse = require('./get-response');
Expand Down Expand Up @@ -50,12 +51,14 @@ module.exports = options => {
fn = electron.net || electron.remote.net;
}

let timings;
const cacheableRequest = new CacheableRequest(fn.request, options.cache);
const cacheReq = cacheableRequest(options, response => {
const {statusCode} = response;
response.retryCount = retryCount;
response.url = redirectUrl || requestUrl;
response.requestUrl = requestUrl;
response.retryCount = retryCount;
response.timings = timings;

const followRedirect = options.followRedirect && 'location' in response.headers;
const redirectGet = followRedirect && getMethodRedirectCodes.has(statusCode);
Expand Down Expand Up @@ -134,6 +137,8 @@ module.exports = options => {
});
});

timings = timer(request);

progress.upload(request, emitter, uploadBodySize);

if (options.gotTimeout) {
Expand Down

0 comments on commit deeb0b7

Please sign in to comment.