diff --git a/packages/preview-process/src/parts/HttpHeader/HttpHeader.ts b/packages/preview-process/src/parts/HttpHeader/HttpHeader.ts index 6edf7f4f..066cc2ac 100644 --- a/packages/preview-process/src/parts/HttpHeader/HttpHeader.ts +++ b/packages/preview-process/src/parts/HttpHeader/HttpHeader.ts @@ -8,5 +8,5 @@ export const ContentType = 'Content-Type' export const CrossOriginEmbedderPolicy = 'Cross-Origin-Embedder-Policy' export const CrossOriginOpenerPolicy = 'Cross-Origin-Opener-Policy' export const CrossOriginResourcePolicy = 'Cross-Origin-Resource-Policy' -export const Etag = 'Etag' +export const Etag = 'ETag' export const IfNotMatch = 'if-none-match' diff --git a/packages/preview-process/src/parts/ToTitleCase/ToTitleCase.ts b/packages/preview-process/src/parts/ToTitleCase/ToTitleCase.ts index 282c5deb..59cd0826 100644 --- a/packages/preview-process/src/parts/ToTitleCase/ToTitleCase.ts +++ b/packages/preview-process/src/parts/ToTitleCase/ToTitleCase.ts @@ -1,4 +1,12 @@ +const SPECIAL_CASES: Record = { + etag: 'ETag', +} + export const toTitleCase = (key: string): string => { + const lowerKey = key.toLowerCase() + if (SPECIAL_CASES[lowerKey]) { + return SPECIAL_CASES[lowerKey] + } return key .split('-') .map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()) diff --git a/packages/preview-process/test/SerializeHeaders.test.ts b/packages/preview-process/test/SerializeHeaders.test.ts index e3ab64c7..a394d787 100644 --- a/packages/preview-process/test/SerializeHeaders.test.ts +++ b/packages/preview-process/test/SerializeHeaders.test.ts @@ -21,7 +21,7 @@ test('serializeHeaders - multiple headers', () => { headers.set('Cross-Origin-Resource-Policy', 'same-origin') expect(SerializeHeaders.serializeHeaders(headers)).toEqual({ 'Content-Type': 'text/plain', - Etag: '"123"', + ETag: '"123"', 'Cross-Origin-Resource-Policy': 'same-origin', }) }) diff --git a/packages/preview-process/test/SerializeResponse.test.ts b/packages/preview-process/test/SerializeResponse.test.ts index e3a16c97..0f7a5fe3 100644 --- a/packages/preview-process/test/SerializeResponse.test.ts +++ b/packages/preview-process/test/SerializeResponse.test.ts @@ -55,7 +55,7 @@ test('serializeResponse - with no content', async () => { init: { status: 304, headers: { - Etag: '"123"', + ETag: '"123"', }, }, }) diff --git a/packages/preview-process/test/ToTitleCase.test.ts b/packages/preview-process/test/ToTitleCase.test.ts index 19022788..d621e3fd 100644 --- a/packages/preview-process/test/ToTitleCase.test.ts +++ b/packages/preview-process/test/ToTitleCase.test.ts @@ -24,3 +24,13 @@ test('toTitleCase - mixed case', () => { test('toTitleCase - multiple hyphens', () => { expect(ToTitleCase.toTitleCase('cross-origin-resource-policy')).toBe('Cross-Origin-Resource-Policy') }) + +test('toTitleCase - etag special case', () => { + expect(ToTitleCase.toTitleCase('etag')).toBe('ETag') +}) + +test('toTitleCase - etag special case with different casing', () => { + expect(ToTitleCase.toTitleCase('ETAG')).toBe('ETag') + expect(ToTitleCase.toTitleCase('ETag')).toBe('ETag') + expect(ToTitleCase.toTitleCase('etAG')).toBe('ETag') +})