Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/internal/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const buildHeaders = (newHeaders: HeadersLike[]): NullableHeaders => {
for (const headers of newHeaders) {
const seenHeaders = new Set<string>();
for (const [name, value] of iterateHeaders(headers)) {
const lowerName = name.toLowerCase();
const lowerName = name.toLocaleLowerCase('en-US');
if (!seenHeaders.has(lowerName)) {
targetHeaders.delete(name);
seenHeaders.add(lowerName);
Expand Down
19 changes: 19 additions & 0 deletions tests/buildHeaders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ describe('buildHeaders', () => {
],
[[undefined], `NullableHeaders { }`],
[[null], `NullableHeaders { }`],
[
[
{
'OpenAI-Organization': 'org-123',
},
],
`NullableHeaders { 'OpenAI-Organization': 'org-123' }`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Expect normalized header names in the new test

This expected value does not match what buildHeaders returns for object inputs: it ultimately stores the entry in a WHATWG Headers, and Headers.append('OpenAI-Organization', ...) normalizes the name to openai-organization on iteration. As written, this new case fails on the standard Node Headers implementation even though the product code lowercases the header name correctly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point, the test should expect the lowercased version since that's what Headers actually returns when you iterate

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point, the test should expect the lowercased version since that's what Headers actually returns when you iterate

],
[
[
{
'OpenAI-Organization': 'org-123',
},
{
'openai-organization': 'org-456',
},
],
`NullableHeaders { 'openai-organization': 'org-456' }`,
],
];
for (const [input, expected] of cases) {
test(expected, () => {
Expand Down