1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-09 15:48:16 -05:00

fix(ext/flash): wrong order of arguments passed to http1Response (#17893)

This commit is contained in:
Kenta Moriuchi 2023-02-23 21:55:40 +09:00 committed by GitHub
parent d5f053dabf
commit 38f9aa0f9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,6 +31,7 @@ const {
PromisePrototypeCatch, PromisePrototypeCatch,
PromisePrototypeThen, PromisePrototypeThen,
SafePromiseAll, SafePromiseAll,
TypedArrayPrototypeSet,
TypedArrayPrototypeSubarray, TypedArrayPrototypeSubarray,
TypeError, TypeError,
Uint8Array, Uint8Array,
@ -114,15 +115,24 @@ const methods = {
let dateInterval; let dateInterval;
let date; let date;
// Construct an HTTP response message. /**
// All HTTP/1.1 messages consist of a start-line followed by a sequence * Construct an HTTP response message.
// of octets. * All HTTP/1.1 messages consist of a start-line followed by a sequence
// * of octets.
// HTTP-message = start-line *
// *( header-field CRLF ) * HTTP-message = start-line
// CRLF * *( header-field CRLF )
// [ message-body ] * 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( function http1Response(
method, method,
status, status,
@ -178,9 +188,9 @@ function http1Response(
str += body ?? ""; str += body ?? "";
} else { } else {
const head = core.encode(str); const head = core.encode(str);
const response = new Uint8Array(head.byteLength + body.byteLength); const response = new Uint8Array(head.byteLength + bodyLen);
response.set(head, 0); TypedArrayPrototypeSet(response, head, 0);
response.set(body, head.byteLength); TypedArrayPrototypeSet(response, body, head.byteLength);
return response; return response;
} }
@ -252,7 +262,7 @@ async function handleResponse(
// If response body length is known, it will be sent synchronously in a // 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 // single op, in other case a "response body" resource will be created and
// we'll be streaming it. // we'll be streaming it.
/** @type {ReadableStream<Uint8Array> | Uint8Array | null} */ /** @type {ReadableStream<Uint8Array> | Uint8Array | string | null} */
let respBody = null; let respBody = null;
let isStreamingResponseBody = false; let isStreamingResponseBody = false;
if (innerResp.body !== null) { if (innerResp.body !== null) {
@ -353,8 +363,8 @@ async function handleResponse(
method, method,
innerResp.status ?? 200, innerResp.status ?? 200,
innerResp.headerList, innerResp.headerList,
0, // Content-Length will be set by the op.
null, null,
0, // Content-Length will be set by the op.
true, true,
), ),
serverId, serverId,
@ -383,8 +393,8 @@ async function handleResponse(
method, method,
innerResp.status ?? 200, innerResp.status ?? 200,
innerResp.headerList, innerResp.headerList,
respBody.byteLength,
null, null,
respBody.byteLength,
), ),
respBody.byteLength, respBody.byteLength,
false, false,