diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js index ea2128c722..b0dd715d17 100644 --- a/ext/fetch/23_request.js +++ b/ext/fetch/23_request.js @@ -16,7 +16,7 @@ import { HTTP_TOKEN_CODE_POINT_RE, } from "ext:deno_web/00_infra.js"; import { URL } from "ext:deno_url/00_url.js"; -import { extractBody, InnerBody, mixinBody } from "ext:deno_fetch/22_body.js"; +import { extractBody, mixinBody } from "ext:deno_fetch/22_body.js"; import { getLocationHref } from "ext:deno_web/12_location.js"; import { extractMimeType } from "ext:deno_web/01_mimesniff.js"; import { blobFromObjectUrl } from "ext:deno_web/09_file.js"; @@ -49,7 +49,6 @@ const _headersCache = Symbol("headers cache"); const _signal = Symbol("signal"); const _mimeType = Symbol("mime type"); const _body = Symbol("body"); -const _flash = Symbol("flash"); const _url = Symbol("url"); const _method = Symbol("method"); @@ -82,7 +81,7 @@ function processUrlList(urlList, urlListProcessed) { */ /** - * @param {() => string} method + * @param {string} method * @param {string | () => string} url * @param {() => [string, string][]} headerList * @param {typeof __window.bootstrap.fetchBody.InnerBody} body @@ -95,15 +94,8 @@ function newInnerRequest(method, url, headerList, body, maybeBlob) { blobUrlEntry = blobFromObjectUrl(url); } return { - methodInner: null, + methodInner: method, get method() { - if (this.methodInner === null) { - try { - this.methodInner = method(); - } catch { - throw new TypeError("cannot read method: request closed"); - } - } return this.methodInner; }, set method(value) { @@ -158,10 +150,9 @@ function newInnerRequest(method, url, headerList, body, maybeBlob) { * https://fetch.spec.whatwg.org/#concept-request-clone * @param {InnerRequest} request * @param {boolean} skipBody - * @param {boolean} flash * @returns {InnerRequest} */ -function cloneInnerRequest(request, skipBody = false, flash = false) { +function cloneInnerRequest(request, skipBody = false) { const headerList = ArrayPrototypeMap( request.headerList, (x) => [x[0], x[1]], @@ -172,19 +163,6 @@ function cloneInnerRequest(request, skipBody = false, flash = false) { body = request.body.clone(); } - if (flash) { - return { - body, - methodCb: request.methodCb, - urlCb: request.urlCb, - headerList: request.headerList, - streamRid: request.streamRid, - serverId: request.serverId, - redirectMode: "follow", - redirectCount: 0, - }; - } - return { method: request.method, headerList, @@ -285,11 +263,7 @@ class Request { return extractMimeType(values); } get [_body]() { - if (this[_flash]) { - return this[_flash].body; - } else { - return this[_request].body; - } + return this[_request].body; } /** @@ -322,7 +296,7 @@ class Request { if (typeof input === "string") { const parsedURL = new URL(input, baseURL); request = newInnerRequest( - () => "GET", + "GET", parsedURL.href, () => [], null, @@ -455,13 +429,8 @@ class Request { if (this[_method]) { return this[_method]; } - if (this[_flash]) { - this[_method] = this[_flash].methodCb(); - return this[_method]; - } else { - this[_method] = this[_request].method; - return this[_method]; - } + this[_method] = this[_request].method; + return this[_method]; } get url() { @@ -470,13 +439,8 @@ class Request { return this[_url]; } - if (this[_flash]) { - this[_url] = this[_flash].urlCb(); - return this[_url]; - } else { - this[_url] = this[_request].url(); - return this[_url]; - } + this[_url] = this[_request].url(); + return this[_url]; } get headers() { @@ -486,9 +450,6 @@ class Request { get redirect() { webidl.assertBranded(this, RequestPrototype); - if (this[_flash]) { - return this[_flash].redirectMode; - } return this[_request].redirectMode; } @@ -502,32 +463,17 @@ class Request { if (this[_body] && this[_body].unusable()) { throw new TypeError("Body is unusable."); } - let newReq; - if (this[_flash]) { - newReq = cloneInnerRequest(this[_flash], false, true); - } else { - newReq = cloneInnerRequest(this[_request]); - } + const newReq = cloneInnerRequest(this[_request]); const newSignal = abortSignal.newSignal(); if (this[_signal]) { abortSignal.follow(newSignal, this[_signal]); } - if (this[_flash]) { - return fromInnerRequest( - newReq, - newSignal, - guardFromHeaders(this[_headers]), - true, - ); - } - return fromInnerRequest( newReq, newSignal, guardFromHeaders(this[_headers]), - false, ); } @@ -606,58 +552,17 @@ function toInnerRequest(request) { * @param {InnerRequest} inner * @param {AbortSignal} signal * @param {"request" | "immutable" | "request-no-cors" | "response" | "none"} guard - * @param {boolean} flash * @returns {Request} */ -function fromInnerRequest(inner, signal, guard, flash) { +function fromInnerRequest(inner, signal, guard) { const request = webidl.createBranded(Request); - if (flash) { - request[_flash] = inner; - } else { - request[_request] = inner; - } + request[_request] = inner; request[_signal] = signal; - request[_getHeaders] = flash - ? () => headersFromHeaderList(inner.headerList(), guard) - : () => headersFromHeaderList(inner.headerList, guard); - return request; -} - -/** - * @param {number} serverId - * @param {number} streamRid - * @param {ReadableStream} body - * @param {() => string} methodCb - * @param {() => string} urlCb - * @param {() => [string, string][]} headersCb - * @returns {Request} - */ -function fromFlashRequest( - serverId, - streamRid, - body, - methodCb, - urlCb, - headersCb, -) { - const request = webidl.createBranded(Request); - request[_flash] = { - body: body !== null ? new InnerBody(body) : null, - methodCb, - urlCb, - headerList: headersCb, - streamRid, - serverId, - redirectMode: "follow", - redirectCount: 0, - }; - request[_getHeaders] = () => headersFromHeaderList(headersCb(), "request"); + request[_getHeaders] = () => headersFromHeaderList(inner.headerList, guard); return request; } export { - _flash, - fromFlashRequest, fromInnerRequest, newInnerRequest, processUrlList, diff --git a/ext/fetch/internal.d.ts b/ext/fetch/internal.d.ts index 65ce31ad91..aec5322bbb 100644 --- a/ext/fetch/internal.d.ts +++ b/ext/fetch/internal.d.ts @@ -78,7 +78,6 @@ declare module "ext:deno_fetch/26_fetch.js" { | "response" | "none", skipBody: boolean, - flash: boolean, ): Request; function redirectStatus(status: number): boolean; function nullBodyStatus(status: number): boolean; diff --git a/ext/http/01_http.js b/ext/http/01_http.js index ab0d6626a7..f434acd3c1 100644 --- a/ext/http/01_http.js +++ b/ext/http/01_http.js @@ -14,7 +14,6 @@ import { toInnerResponse, } from "ext:deno_fetch/23_response.js"; import { - _flash, fromInnerRequest, newInnerRequest, toInnerRequest, @@ -134,7 +133,7 @@ class HttpConn { } const innerRequest = newInnerRequest( - () => method, + method, url, () => ops.op_http_headers(streamRid), body !== null ? new InnerBody(body) : null, @@ -467,12 +466,6 @@ function upgradeWebSocket(request, options = {}) { } function upgradeHttp(req) { - if (req[_flash]) { - throw new TypeError( - "Flash requests can not be upgraded with `upgradeHttp`. Use `upgradeHttpRaw` instead.", - ); - } - req[_deferred] = new Deferred(); return req[_deferred].promise; }