summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-04-12 15:24:45 +0100
committerGitHub <noreply@github.com>2021-04-12 10:24:45 -0400
commita20504642d083172f297543f9788b128e9c2e0bc (patch)
treed575d8646c698dbbb9cad71f25036efbb00f0f59 /runtime/js
parent9d53dab4df64361f00dda2534eecbd04797d56a2 (diff)
fix(runtime/js/http): Correctly parse user response headers (#10076)
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/40_http.js31
1 files changed, 12 insertions, 19 deletions
diff --git a/runtime/js/40_http.js b/runtime/js/40_http.js
index dd6c99a2d..d9dff7b52 100644
--- a/runtime/js/40_http.js
+++ b/runtime/js/40_http.js
@@ -9,15 +9,6 @@
const core = window.Deno.core;
const { ReadableStream } = window.__bootstrap.streams;
- function flatEntries(obj) {
- const entries = [];
- for (const key in obj) {
- entries.push(key);
- entries.push(obj[key]);
- }
- return entries;
- }
-
function serveHttp(conn) {
const rid = Deno.core.jsonOpSync("op_http_start", conn.rid);
return new HttpConn(rid);
@@ -104,12 +95,14 @@
);
}
- function respond(responseSenderRid, resp, zeroCopyBuf) {
- return Deno.core.jsonOpSync("op_http_response", [
- responseSenderRid,
- resp.status ?? 200,
- flatEntries(resp.headers ?? {}),
- ], zeroCopyBuf);
+ /** IMPORTANT: Equivalent to `Array.from(headers).flat()` but more performant.
+ * Please preserve. */
+ function flattenHeaders(headers) {
+ const array = [];
+ for (const pair of headers) {
+ array.push(pair[0], pair[1]);
+ }
+ return array;
}
function createRespondWith(responseSenderRid, connRid) {
@@ -136,11 +129,11 @@
zeroCopyBuf = null;
}
- const responseBodyRid = respond(
+ const responseBodyRid = Deno.core.jsonOpSync("op_http_response", [
responseSenderRid,
- resp,
- zeroCopyBuf,
- );
+ resp.status ?? 200,
+ flattenHeaders(resp.headers),
+ ], zeroCopyBuf);
// If `respond` returns a responseBodyRid, we should stream the body
// to that resource.