Skip to content

Commit 983540f

Browse files
authored
fix: manage Headers instances in the JS kit (#235)
1 parent a7bf26b commit 983540f

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

kits/javascript/shims/types/headers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ class Headers {
99

1010
// Initialize the headers
1111
for (const key in initialHeaders) {
12-
headers[key] = initialHeaders[key];
12+
let value = initialHeaders[key];
13+
14+
// Allow only string values
15+
if (typeof value === "string") {
16+
headers[key] = value;
17+
}
1318
}
1419

1520
this.headers = headers;

kits/javascript/shims/types/response.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ import httpStatus from "http-status";
1010
class Response {
1111
constructor(body, options = {}) {
1212
this.body = body;
13-
this.headers = new Headers(options.headers || {});
13+
14+
if (options.headers instanceof Headers) {
15+
this.headers = options.headers;
16+
} else if (options.headers instanceof Object) {
17+
this.headers = new Headers(options.headers);
18+
} else {
19+
this.headers = new Headers({});
20+
}
21+
1422
this.status = options.status || 200;
1523
this.statusText = options.statusText || httpStatus[this.status];
1624
}
Binary file not shown.

0 commit comments

Comments
 (0)