summaryrefslogtreecommitdiff
path: root/ext/fetch/23_request.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fetch/23_request.js')
-rw-r--r--ext/fetch/23_request.js47
1 files changed, 24 insertions, 23 deletions
diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js
index a59bfb29d..bbaf886a6 100644
--- a/ext/fetch/23_request.js
+++ b/ext/fetch/23_request.js
@@ -10,6 +10,7 @@
/// <reference lib="esnext" />
import * as webidl from "ext:deno_webidl/00_webidl.js";
+import { assert } from "ext:deno_web/00_infra.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import {
byteUpperCase,
@@ -356,21 +357,19 @@ class Request {
request.clientRid = init.client?.rid ?? null;
}
- // 27.
- this[_request] = request;
-
// 28.
- this[_signal] = abortSignal.newSignal();
+ this[_request] = request;
// 29.
- if (signal !== null) {
- abortSignal.follow(this[_signal], signal);
- }
+ const signals = signal !== null ? [signal] : [];
// 30.
+ this[_signal] = abortSignal.createDependentAbortSignal(signals, prefix);
+
+ // 31.
this[_headers] = headersFromHeaderList(request.headerList, "request");
- // 32.
+ // 33.
if (init.headers || ObjectKeys(init).length > 0) {
const headerList = headerListFromHeaders(this[_headers]);
const headers = init.headers ?? ArrayPrototypeSlice(
@@ -384,13 +383,13 @@ class Request {
fillHeaders(this[_headers], headers);
}
- // 33.
+ // 34.
let inputBody = null;
if (ObjectPrototypeIsPrototypeOf(RequestPrototype, input)) {
inputBody = input[_body];
}
- // 34.
+ // 35.
if (
(request.method === "GET" || request.method === "HEAD") &&
((init.body !== undefined && init.body !== null) ||
@@ -399,10 +398,10 @@ class Request {
throw new TypeError("Request with GET/HEAD method cannot have body.");
}
- // 35.
+ // 36.
let initBody = null;
- // 36.
+ // 37.
if (init.body !== undefined && init.body !== null) {
const res = extractBody(init.body);
initBody = res.body;
@@ -411,13 +410,13 @@ class Request {
}
}
- // 37.
+ // 38.
const inputOrInitBody = initBody ?? inputBody;
- // 39.
+ // 40.
let finalBody = inputOrInitBody;
- // 40.
+ // 41.
if (initBody === null && inputBody !== null) {
if (input[_body] && input[_body].unusable()) {
throw new TypeError("Input request's body is unusable.");
@@ -425,7 +424,7 @@ class Request {
finalBody = inputBody.createProxy();
}
- // 41.
+ // 42.
request.body = finalBody;
}
@@ -464,20 +463,22 @@ class Request {
}
clone() {
+ const prefix = "Failed to call 'Request.clone'";
webidl.assertBranded(this, RequestPrototype);
if (this[_body] && this[_body].unusable()) {
throw new TypeError("Body is unusable.");
}
- const newReq = cloneInnerRequest(this[_request]);
- const newSignal = abortSignal.newSignal();
+ const clonedReq = cloneInnerRequest(this[_request]);
- if (this[_signal]) {
- abortSignal.follow(newSignal, this[_signal]);
- }
+ assert(this[_signal] !== null);
+ const clonedSignal = abortSignal.createDependentAbortSignal(
+ [this[_signal]],
+ prefix,
+ );
return fromInnerRequest(
- newReq,
- newSignal,
+ clonedReq,
+ clonedSignal,
guardFromHeaders(this[_headers]),
);
}