diff --git a/src/shared/transport.ts b/src/shared/transport.ts index f9b21bed32..242493cc25 100644 --- a/src/shared/transport.ts +++ b/src/shared/transport.ts @@ -6,7 +6,7 @@ export type FetchLike = (url: string | URL, init?: RequestInit) => Promise for manipulation. * Handles Headers objects, arrays of tuples, and plain objects. */ -export function normalizeHeaders(headers: HeadersInit | undefined): Record { +export function normalizeHeaders(headers: RequestInit['headers'] | undefined): Record { if (!headers) return {}; if (headers instanceof Headers) { diff --git a/test/shared/transport.test.ts b/test/shared/transport.test.ts new file mode 100644 index 0000000000..e12e6fd672 --- /dev/null +++ b/test/shared/transport.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, test } from 'vitest'; +import { normalizeHeaders } from '../../src/shared/transport.js'; + +describe('normalizeHeaders', () => { + test('returns empty object for undefined', () => { + expect(normalizeHeaders(undefined)).toEqual({}); + }); + + test('copies plain object', () => { + const input = { 'Content-Type': 'application/json', 'X-Custom': 'value' }; + const result = normalizeHeaders(input); + expect(result).toEqual(input); + }); + + test('normalizes array of tuples', () => { + const result = normalizeHeaders([['Content-Type', 'text/plain'], ['Accept', '*/*']]); + expect(result).toEqual({ 'Content-Type': 'text/plain', 'Accept': '*/*' }); + }); + + test('accepts Headers instance', () => { + const h = new Headers(); + h.set('Authorization', 'Bearer token'); + const result = normalizeHeaders(h); + expect(result).toEqual({ 'authorization': 'Bearer token' }); + }); +});