Skip to content

Commit 7faea45

Browse files
committed
fix headers object to accept duplicated keys like set-cookie
1 parent 11b802f commit 7faea45

6 files changed

+24
-8
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[![JSR](https://jsr.io/badges/@deco/warp)](https://jsr.io/@deco/warp)
22
[![JSR Score](https://jsr.io/badges/@deco/warp/score)](https://jsr.io/@deco/warp)
33

4-
54
# Warp
65

76
**Warp** is a simple tool that allows your locally running HTTP(s) servers to

deno.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deco/warp",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"exports": "./mod.ts",
55
"tasks": {
66
"check": "deno fmt && deno lint && deno check mod.ts"

handlers.client.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,22 @@ async function doFetch(
220220
signal,
221221
},
222222
);
223+
224+
const headers: Record<string, Array<string>> = {};
225+
226+
for (const [key, value] of response.headers.entries()) {
227+
headers[key] ??= [];
228+
headers[key].push(value);
229+
}
230+
223231
await clientCh.send({
224232
type: "response-start",
225233
id: request.id,
226234
statusCode: response.status,
227235
statusMessage: response.statusText,
228-
headers: Object.fromEntries(response.headers.entries()),
236+
headers,
229237
});
238+
230239
const body = response?.body;
231240
const stream = body ? makeChanStream(body) : undefined;
232241
for await (const chunk of stream?.recv(signal) ?? []) {

handlers.server.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ const onResponseStart: ClientMessageHandler<ResponseStartMessage> = (
3535
return;
3636
}
3737
const headers = new Headers();
38-
Object.entries(message.headers).forEach(([key, value]: [string, string]) => {
39-
headers.set(key, value);
40-
});
38+
Object.entries(message.headers).forEach(
39+
([key, value]: [string, string | Array<string>]) => {
40+
if (typeof value === "string") {
41+
headers.set(key, value);
42+
} else if (Array.isArray(value)) {
43+
value.forEach((v) => {
44+
headers.append(key, v);
45+
});
46+
}
47+
},
48+
);
4149
const shouldBeNullBody = NULL_BODIES.includes(message.statusCode);
4250
const stream = !shouldBeNullBody && request.responseBodyChan
4351
? makeReadableStream(request.responseBodyChan)

messages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface ResponseStartMessage {
1919
id: string;
2020
statusCode: number;
2121
statusMessage: string;
22-
headers: Record<string, string>;
22+
headers: Record<string, Array<string>>;
2323
}
2424
export interface DataMessage {
2525
type: "data";

0 commit comments

Comments
 (0)