Skip to content

Commit

Permalink
fix: manage Headers instances in the JS kit (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelmmiguel authored Oct 16, 2023
1 parent a7bf26b commit 983540f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion kits/javascript/shims/types/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class Headers {

// Initialize the headers
for (const key in initialHeaders) {
headers[key] = initialHeaders[key];
let value = initialHeaders[key];

// Allow only string values
if (typeof value === "string") {
headers[key] = value;
}
}

this.headers = headers;
Expand Down
10 changes: 9 additions & 1 deletion kits/javascript/shims/types/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import httpStatus from "http-status";
class Response {
constructor(body, options = {}) {
this.body = body;
this.headers = new Headers(options.headers || {});

if (options.headers instanceof Headers) {
this.headers = options.headers;
} else if (options.headers instanceof Object) {
this.headers = new Headers(options.headers);
} else {
this.headers = new Headers({});
}

this.status = options.status || 200;
this.statusText = options.statusText || httpStatus[this.status];
}
Expand Down
Binary file modified kits/javascript/wasm-workers-quick-js-engine.wasm
Binary file not shown.

0 comments on commit 983540f

Please sign in to comment.