|
|
4 年前 | |
|---|---|---|
| .. | ||
| source | 4 年前 | |
| LICENSE | 4 年前 | |
| README.md | 4 年前 | |
| package.json | 4 年前 | |
Timings for HTTP requests
Inspired by the request package.
'use strict';
const https = require('https');
const timer = require('@szmarczak/http-timer');
const request = https.get('https://httpbin.org/anything');
const timings = timer(request);
request.on('response', response => {
response.on('data', () => {}); // Consume the data somehow
response.on('end', () => {
console.log(timings);
});
});
// { start: 1535708511443,
// socket: 1535708511444,
// lookup: 1535708511444,
// connect: 1535708511582,
// upload: 1535708511887,
// response: 1535708512037,
// end: 1535708512040,
// phases:
// { wait: 1,
// dns: 0,
// tcp: 138,
// request: 305,
// firstByte: 150,
// download: 3,
// total: 597 } }
Returns: Object
start - Time when the request started.socket - Time when a socket was assigned to the request.lookup - Time when the DNS lookup finished.connect - Time when the socket successfully connected.upload - Time when the request finished uploading.response - Time when the request fired the response event.end - Time when the response fired the end event.error - Time when the request fired the error event.phases
wait - timings.socket - timings.startdns - timings.lookup - timings.sockettcp - timings.connect - timings.lookuprequest - timings.upload - timings.connectfirstByte - timings.response - timings.uploaddownload - timings.end - timings.responsetotal - timings.end - timings.start or timings.error - timings.startNote: The time is a number representing the milliseconds elapsed since the UNIX epoch.
MIT