| 76 | * `Response.headers` already lower-cases, but we normalise explicitly |
| 77 | * to stay robust against test mocks that construct `Headers` loosely. */ |
| 78 | const readHeader = (headers: Readonly<Record<string, string>>, name: string): string | null => { |
| 79 | const direct = headers[name]; |
| 80 | if (direct !== undefined) return direct; |
| 81 | const lower = name.toLowerCase(); |
| 82 | for (const [k, v] of Object.entries(headers)) { |
| 83 | if (k.toLowerCase() === lower) return v; |
| 84 | } |
| 85 | return null; |
| 86 | }; |
| 87 | |
| 88 | /** Statuses that mean "you are not authenticated for this resource". |
| 89 | * |