summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenta Moriuchi <moriken@kimamass.com>2023-02-23 21:55:40 +0900
committerGitHub <noreply@github.com>2023-02-23 18:25:40 +0530
commit38f9aa0f9c8e80ca62db853e93d06b96d3596500 (patch)
tree8fd340a3d6cdfade3ecf85f3ff295ab0558a9ece
parentd5f053dabfadb2a62a4cc6b89a6b7bf64ce3c460 (diff)
fix(ext/flash): wrong order of arguments passed to `http1Response` (#17893)
-rw-r--r--ext/flash/01_http.js40
1 files changed, 25 insertions, 15 deletions
diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js
index ff2eab63c..79a4963a5 100644
--- a/ext/flash/01_http.js
+++ b/ext/flash/01_http.js
@@ -31,6 +31,7 @@ const {
PromisePrototypeCatch,
PromisePrototypeThen,
SafePromiseAll,
+ TypedArrayPrototypeSet,
TypedArrayPrototypeSubarray,
TypeError,
Uint8Array,
@@ -114,15 +115,24 @@ const methods = {
let dateInterval;
let date;
-// Construct an HTTP response message.
-// All HTTP/1.1 messages consist of a start-line followed by a sequence
-// of octets.
-//
-// HTTP-message = start-line
-// *( header-field CRLF )
-// CRLF
-// [ message-body ]
-//
+/**
+ * Construct an HTTP response message.
+ * All HTTP/1.1 messages consist of a start-line followed by a sequence
+ * of octets.
+ *
+ * HTTP-message = start-line
+ * *( header-field CRLF )
+ * CRLF
+ * [ message-body ]
+ *
+ * @param {keyof typeof methods} method
+ * @param {keyof typeof statusCodes} status
+ * @param {[name: string, value: string][]} headerList
+ * @param {Uint8Array | string | null} body
+ * @param {number} bodyLen
+ * @param {boolean} earlyEnd
+ * @returns {Uint8Array | string}
+ */
function http1Response(
method,
status,
@@ -178,9 +188,9 @@ function http1Response(
str += body ?? "";
} else {
const head = core.encode(str);
- const response = new Uint8Array(head.byteLength + body.byteLength);
- response.set(head, 0);
- response.set(body, head.byteLength);
+ const response = new Uint8Array(head.byteLength + bodyLen);
+ TypedArrayPrototypeSet(response, head, 0);
+ TypedArrayPrototypeSet(response, body, head.byteLength);
return response;
}
@@ -252,7 +262,7 @@ async function handleResponse(
// If response body length is known, it will be sent synchronously in a
// single op, in other case a "response body" resource will be created and
// we'll be streaming it.
- /** @type {ReadableStream<Uint8Array> | Uint8Array | null} */
+ /** @type {ReadableStream<Uint8Array> | Uint8Array | string | null} */
let respBody = null;
let isStreamingResponseBody = false;
if (innerResp.body !== null) {
@@ -353,8 +363,8 @@ async function handleResponse(
method,
innerResp.status ?? 200,
innerResp.headerList,
- 0, // Content-Length will be set by the op.
null,
+ 0, // Content-Length will be set by the op.
true,
),
serverId,
@@ -383,8 +393,8 @@ async function handleResponse(
method,
innerResp.status ?? 200,
innerResp.headerList,
- respBody.byteLength,
null,
+ respBody.byteLength,
),
respBody.byteLength,
false,