|
| 1 | +/** @type {Record<string, string | undefined>} */ |
| 2 | +const headerNameLowerCasedRecord = {} |
| 3 | + |
| 4 | +// https://developer.mozilla.org/docs/Web/HTTP/Headers |
| 5 | +const wellknownHeaderNames = [ |
| 6 | + 'Accept', |
| 7 | + 'Accept-Encoding', |
| 8 | + 'Accept-Language', |
| 9 | + 'Accept-Ranges', |
| 10 | + 'Access-Control-Allow-Credentials', |
| 11 | + 'Access-Control-Allow-Headers', |
| 12 | + 'Access-Control-Allow-Methods', |
| 13 | + 'Access-Control-Allow-Origin', |
| 14 | + 'Access-Control-Expose-Headers', |
| 15 | + 'Access-Control-Max-Age', |
| 16 | + 'Access-Control-Request-Headers', |
| 17 | + 'Access-Control-Request-Method', |
| 18 | + 'Age', |
| 19 | + 'Allow', |
| 20 | + 'Alt-Svc', |
| 21 | + 'Alt-Used', |
| 22 | + 'Authorization', |
| 23 | + 'Cache-Control', |
| 24 | + 'Clear-Site-Data', |
| 25 | + 'Connection', |
| 26 | + 'Content-Disposition', |
| 27 | + 'Content-Encoding', |
| 28 | + 'Content-Language', |
| 29 | + 'Content-Length', |
| 30 | + 'Content-Location', |
| 31 | + 'Content-Range', |
| 32 | + 'Content-Security-Policy', |
| 33 | + 'Content-Security-Policy-Report-Only', |
| 34 | + 'Content-Type', |
| 35 | + 'Cookie', |
| 36 | + 'Cross-Origin-Embedder-Policy', |
| 37 | + 'Cross-Origin-Opener-Policy', |
| 38 | + 'Cross-Origin-Resource-Policy', |
| 39 | + 'Date', |
| 40 | + 'Device-Memory', |
| 41 | + 'Downlink', |
| 42 | + 'ECT', |
| 43 | + 'ETag', |
| 44 | + 'Expect', |
| 45 | + 'Expect-CT', |
| 46 | + 'Expires', |
| 47 | + 'Forwarded', |
| 48 | + 'From', |
| 49 | + 'Host', |
| 50 | + 'If-Match', |
| 51 | + 'If-Modified-Since', |
| 52 | + 'If-None-Match', |
| 53 | + 'If-Range', |
| 54 | + 'If-Unmodified-Since', |
| 55 | + 'Keep-Alive', |
| 56 | + 'Last-Modified', |
| 57 | + 'Link', |
| 58 | + 'Location', |
| 59 | + 'Max-Forwards', |
| 60 | + 'Origin', |
| 61 | + 'Permissions-Policy', |
| 62 | + 'Pragma', |
| 63 | + 'Proxy-Authenticate', |
| 64 | + 'Proxy-Authorization', |
| 65 | + 'RTT', |
| 66 | + 'Range', |
| 67 | + 'Referer', |
| 68 | + 'Referrer-Policy', |
| 69 | + 'Refresh', |
| 70 | + 'Retry-After', |
| 71 | + 'Sec-WebSocket-Accept', |
| 72 | + 'Sec-WebSocket-Extensions', |
| 73 | + 'Sec-WebSocket-Key', |
| 74 | + 'Sec-WebSocket-Protocol', |
| 75 | + 'Sec-WebSocket-Version', |
| 76 | + 'Server', |
| 77 | + 'Server-Timing', |
| 78 | + 'Service-Worker-Allowed', |
| 79 | + 'Service-Worker-Navigation-Preload', |
| 80 | + 'Set-Cookie', |
| 81 | + 'SourceMap', |
| 82 | + 'Strict-Transport-Security', |
| 83 | + 'Supports-Loading-Mode', |
| 84 | + 'TE', |
| 85 | + 'Timing-Allow-Origin', |
| 86 | + 'Trailer', |
| 87 | + 'Transfer-Encoding', |
| 88 | + 'Upgrade', |
| 89 | + 'Upgrade-Insecure-Requests', |
| 90 | + 'User-Agent', |
| 91 | + 'Vary', |
| 92 | + 'Via', |
| 93 | + 'WWW-Authenticate', |
| 94 | + 'X-Content-Type-Options', |
| 95 | + 'X-DNS-Prefetch-Control', |
| 96 | + 'X-Frame-Options', |
| 97 | + 'X-Permitted-Cross-Domain-Policies', |
| 98 | + 'X-Powered-By', |
| 99 | + 'X-Requested-With', |
| 100 | + 'X-XSS-Protection' |
| 101 | +] |
| 102 | + |
| 103 | +for (let i = 0; i < wellknownHeaderNames.length; ++i) { |
| 104 | + const key = wellknownHeaderNames[i] |
| 105 | + const lowerCasedKey = key.toLowerCase() |
| 106 | + headerNameLowerCasedRecord[key] = headerNameLowerCasedRecord[lowerCasedKey] = |
| 107 | + lowerCasedKey |
| 108 | +} |
| 109 | + |
| 110 | +// Note: object prototypes should not be able to be referenced. e.g. `Object#hasOwnProperty`. |
| 111 | +Object.setPrototypeOf(headerNameLowerCasedRecord, null) |
| 112 | + |
| 113 | +module.exports = { |
| 114 | + wellknownHeaderNames, |
| 115 | + headerNameLowerCasedRecord |
| 116 | +} |
0 commit comments