( response: Response, info: RateLimitInfo, windowMs: number, )
| 84 | * @param windowMs {number} - The window length. |
| 85 | */ |
| 86 | export 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. |
no test coverage detected
searching dependent graphs…