mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
parent
55e0483626
commit
39223f709b
4 changed files with 170 additions and 43 deletions
|
@ -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.
|
||||
// 28.
|
||||
this[_request] = request;
|
||||
|
||||
// 28.
|
||||
this[_signal] = abortSignal.newSignal();
|
||||
|
||||
// 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]),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue