MCPcopy
hub / github.com/tinyhttp/tinyhttp / ping

Function ping

packages/ping/src/index.ts:6–21  ·  view source on GitHub ↗
(opts?: { round?: boolean })

Source from the content-addressed store, hash-verified

4 * Add X-Response-Time header field.
5 */
6export function ping(opts?: { round?: boolean }) {
7 return function responseTime(_: Request, res: Response, next: (err?: any) => void): void {
8 const start = process.hrtime()
9
10 const delta = process.hrtime(start)
11
12 // Format to high resolution time with nano time
13 let time = delta[0] * 1000 + delta[1] / 1000000
14
15 if (!opts?.round) time = Math.round(time)
16
17 res.setHeader('X-Response-Time', `${time}ms`)
18
19 next()
20 }
21}

Callers 1

ping.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected