MCPcopy
hub / github.com/express-rate-limit/express-rate-limit / setDraft6Headers

Function setDraft6Headers

source/headers.ts:86–103  ·  view source on GitHub ↗
(
	response: Response,
	info: RateLimitInfo,
	windowMs: number,
)

Source from the content-addressed store, hash-verified

84 * @param windowMs {number} - The window length.
85 */
86export const setDraft6Headers = (
87 response: Response,
88 info: RateLimitInfo,
89 windowMs: number,
90): void => {
91 if (response.headersSent) return
92
93 const windowSeconds = Math.ceil(windowMs / 1000)
94 const resetSeconds = getResetSeconds(windowMs, info.resetTime)
95
96 response.setHeader('RateLimit-Policy', `${info.limit};w=${windowSeconds}`)
97 response.setHeader('RateLimit-Limit', info.limit.toString())
98 response.setHeader('RateLimit-Remaining', info.remaining.toString())
99
100 // Set this header only if the store returns a `resetTime`.
101 if (typeof resetSeconds === 'number')
102 response.setHeader('RateLimit-Reset', resetSeconds.toString())
103}
104
105/**
106 * Sets `RateLimit` & `RateLimit-Policy` headers based on the seventh draft of the spec.

Callers 2

rateLimitFunction · 0.85
headers-test.tsFile · 0.85

Calls 1

getResetSecondsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…