fix: use callable .get to detect Headers in pickRequestHost

This commit is contained in:
Linus Rath
2026-07-09 13:51:12 +02:00
parent e933800792
commit 38313639ed
2 changed files with 19 additions and 1 deletions
+10
View File
@@ -111,6 +111,16 @@ describe('pickRequestHost', () => {
it('lower-cases the result', () => {
expect(pickRequestHost(mockHeaders({ host: 'EXAMPLE.com' }))).toBe('example.com');
});
it('handles a ReadonlyHeaders-shaped object with an internal `headers` field', () => {
// `await headers()` returns Next's ReadonlyHeaders, which exposes `.get`
// directly but also carries an internal `headers` property. Ensure we use
// its own `.get` rather than descending into `.headers` (#585).
const readonlyLike = Object.assign(mockHeaders({ host: 'ro.example.com' }), {
headers: { notCallable: true },
});
expect(pickRequestHost(readonlyLike as unknown as Headers)).toBe('ro.example.com');
});
});
describe('matchDomainBranding', () => {