http-timer

Timings for HTTP requests

Github星跟蹤圖

http-timer

Timings for HTTP requests

Build Status
Coverage Status
install size

Inspired by the request package.

Installation

NPM:

npm install @szmarczak/http-timer

Yarn:

yarn add @szmarczak/http-timer

Usage

const https = require('https');
const timer = require('@szmarczak/http-timer');

const request = https.get('https://httpbin.org/anything');
timer(request);

request.once('response', response => {
	response.resume();
	response.once('end', () => {
		console.log(response.timings); // You can use `request.timings` as well
	});
});

// {
//   start: 1572712180361,
//   socket: 1572712180362,
//   lookup: 1572712180415,
//   connect: 1572712180571,
//   upload: 1572712180884,
//   response: 1572712181037,
//   end: 1572712181039,
//   error: undefined,
//   abort: undefined,
//   phases: {
//     wait: 1,
//     dns: 53,
//     tcp: 156,
//     request: 313,
//     firstByte: 153,
//     download: 2,
//     total: 678
//   }
// }

API

timer(request)

Returns: Object

Note: The time is a number representing the milliseconds elapsed since the UNIX epoch.

  • 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.
  • secureConnect - Time when the socket securely connected.
  • upload - Time when the request finished uploading.
  • response - Time when the request fired response event.
  • end - Time when the response fired end event.
  • error - Time when the request fired error event.
  • abort - Time when the request fired abort event.
  • phases
    • wait - timings.socket - timings.start
    • dns - timings.lookup - timings.socket
    • tcp - timings.connect - timings.lookup
    • tls - timings.secureConnect - timings.connect
    • request - timings.upload - (timings.secureConnect, timings.connect)
    • firstByte - timings.response - timings.upload
    • download - timings.end - timings.response
    • total - (timings.end, timings.error, timings.abort) - timings.start

If something has not been measured yet, it will be undefined.

License

MIT

主要指標

概覽
名稱與所有者szmarczak/http-timer
主編程語言TypeScript
編程語言TypeScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2018-08-24 19:39:03
推送於2021-08-20 23:26:47
最后一次提交2021-08-21 01:26:09
發布數16
最新版本名稱v5.0.1 (發布於 )
第一版名稱1.0.2 (發布於 )
用户参与
星數193
關注者數3
派生數18
提交數49
已啟用問題?
問題數30
打開的問題數6
拉請求數5
打開的拉請求數0
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?