Skip to content

Commit ba252e7

Browse files
committed
refactor: better node support for set-cookie header always being an array
1 parent acd6119 commit ba252e7

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

docs/interfaces/Headers.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Concrete interface that the headers map should implement.
66

77
## Indexable
88

9-
[key: `string`]: `string` \| `undefined`
9+
[key: `string`]: `string` \| `string`[] \| `undefined`
1010

1111
## Table of contents
1212

@@ -15,6 +15,7 @@ Concrete interface that the headers map should implement.
1515
- [accept](Headers.md#accept)
1616
- [allow](Headers.md#allow)
1717
- [content-type](Headers.md#content-type)
18+
- [set-cookie](Headers.md#set-cookie)
1819

1920
## Properties
2021

@@ -33,3 +34,13 @@ ___
3334
### content-type
3435

3536
`Optional` **content-type**: `string`
37+
38+
___
39+
40+
### set-cookie
41+
42+
`Optional` **set-cookie**: `string` \| `string`[]
43+
44+
Always an array in Node. Duplicates are added to it.
45+
Not necessarily true for other environments, make sure
46+
to check the type during runtime.

src/__tests__/utils/tserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function startTServer(
3333
const [body, init] = await handle({
3434
url: req.url,
3535
method: req.method,
36-
headers: req.headers as Record<string, string>,
36+
headers: req.headers,
3737
body: await new Promise<string>((resolve) => {
3838
let body = '';
3939
req.on('data', (chunk) => (body += chunk));

src/common.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ export interface Headers {
1515
accept?: string | undefined;
1616
allow?: string | undefined;
1717
'content-type'?: string | undefined;
18-
[key: string]: string | undefined;
18+
/**
19+
* Always an array in Node. Duplicates are added to it.
20+
* Not necessarily true for other environments, make sure
21+
* to check the type during runtime.
22+
*/
23+
'set-cookie'?: string | string[] | undefined;
24+
[key: string]: string | string[] | undefined;
1925
}
2026

2127
/**

0 commit comments

Comments
 (0)