Skip to content

Commit 880a505

Browse files
committed
fix(core): preserve numeric header values in headersToDict
1 parent b92be48 commit 880a505

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

packages/core/src/utils/request.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export function headersToDict(
7070
Object.entries(reqHeaders).forEach(([key, value]) => {
7171
if (typeof value === 'string') {
7272
headers[key] = value;
73+
} else if (typeof value === 'number') {
74+
headers[key] = String(value);
7375
}
7476
});
7577
} catch {

packages/core/test/lib/utils/request.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ describe('request utils', () => {
4949
key3: 'value3',
5050
});
5151
});
52+
53+
it('stringifies numeric values (e.g. OutgoingHttpHeaders content-length)', () => {
54+
expect(
55+
headersToDict({
56+
'content-length': 42,
57+
'x-string': 'hello',
58+
'x-undef': undefined,
59+
}),
60+
).toEqual({
61+
'content-length': '42',
62+
'x-string': 'hello',
63+
});
64+
});
5265
});
5366

5467
describe('winterCGRequestToRequestData', () => {

0 commit comments

Comments
 (0)