mirror of
https://github.com/denoland/deno.git
synced 2025-01-12 00:54:02 -05:00
refactor: remove remaining references to "flash" server (#18580)
Follow up to https://github.com/denoland/deno/pull/18578 We will need to do another pass cleaning up `ext/fetch/23_request.js`
This commit is contained in:
parent
62c5664697
commit
c341dbee5d
3 changed files with 15 additions and 118 deletions
|
@ -16,7 +16,7 @@ import {
|
||||||
HTTP_TOKEN_CODE_POINT_RE,
|
HTTP_TOKEN_CODE_POINT_RE,
|
||||||
} from "ext:deno_web/00_infra.js";
|
} from "ext:deno_web/00_infra.js";
|
||||||
import { URL } from "ext:deno_url/00_url.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 { getLocationHref } from "ext:deno_web/12_location.js";
|
||||||
import { extractMimeType } from "ext:deno_web/01_mimesniff.js";
|
import { extractMimeType } from "ext:deno_web/01_mimesniff.js";
|
||||||
import { blobFromObjectUrl } from "ext:deno_web/09_file.js";
|
import { blobFromObjectUrl } from "ext:deno_web/09_file.js";
|
||||||
|
@ -49,7 +49,6 @@ const _headersCache = Symbol("headers cache");
|
||||||
const _signal = Symbol("signal");
|
const _signal = Symbol("signal");
|
||||||
const _mimeType = Symbol("mime type");
|
const _mimeType = Symbol("mime type");
|
||||||
const _body = Symbol("body");
|
const _body = Symbol("body");
|
||||||
const _flash = Symbol("flash");
|
|
||||||
const _url = Symbol("url");
|
const _url = Symbol("url");
|
||||||
const _method = Symbol("method");
|
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} url
|
||||||
* @param {() => [string, string][]} headerList
|
* @param {() => [string, string][]} headerList
|
||||||
* @param {typeof __window.bootstrap.fetchBody.InnerBody} body
|
* @param {typeof __window.bootstrap.fetchBody.InnerBody} body
|
||||||
|
@ -95,15 +94,8 @@ function newInnerRequest(method, url, headerList, body, maybeBlob) {
|
||||||
blobUrlEntry = blobFromObjectUrl(url);
|
blobUrlEntry = blobFromObjectUrl(url);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
methodInner: null,
|
methodInner: method,
|
||||||
get method() {
|
get method() {
|
||||||
if (this.methodInner === null) {
|
|
||||||
try {
|
|
||||||
this.methodInner = method();
|
|
||||||
} catch {
|
|
||||||
throw new TypeError("cannot read method: request closed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.methodInner;
|
return this.methodInner;
|
||||||
},
|
},
|
||||||
set method(value) {
|
set method(value) {
|
||||||
|
@ -158,10 +150,9 @@ function newInnerRequest(method, url, headerList, body, maybeBlob) {
|
||||||
* https://fetch.spec.whatwg.org/#concept-request-clone
|
* https://fetch.spec.whatwg.org/#concept-request-clone
|
||||||
* @param {InnerRequest} request
|
* @param {InnerRequest} request
|
||||||
* @param {boolean} skipBody
|
* @param {boolean} skipBody
|
||||||
* @param {boolean} flash
|
|
||||||
* @returns {InnerRequest}
|
* @returns {InnerRequest}
|
||||||
*/
|
*/
|
||||||
function cloneInnerRequest(request, skipBody = false, flash = false) {
|
function cloneInnerRequest(request, skipBody = false) {
|
||||||
const headerList = ArrayPrototypeMap(
|
const headerList = ArrayPrototypeMap(
|
||||||
request.headerList,
|
request.headerList,
|
||||||
(x) => [x[0], x[1]],
|
(x) => [x[0], x[1]],
|
||||||
|
@ -172,19 +163,6 @@ function cloneInnerRequest(request, skipBody = false, flash = false) {
|
||||||
body = request.body.clone();
|
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 {
|
return {
|
||||||
method: request.method,
|
method: request.method,
|
||||||
headerList,
|
headerList,
|
||||||
|
@ -285,12 +263,8 @@ class Request {
|
||||||
return extractMimeType(values);
|
return extractMimeType(values);
|
||||||
}
|
}
|
||||||
get [_body]() {
|
get [_body]() {
|
||||||
if (this[_flash]) {
|
|
||||||
return this[_flash].body;
|
|
||||||
} else {
|
|
||||||
return this[_request].body;
|
return this[_request].body;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://fetch.spec.whatwg.org/#dom-request
|
* https://fetch.spec.whatwg.org/#dom-request
|
||||||
|
@ -322,7 +296,7 @@ class Request {
|
||||||
if (typeof input === "string") {
|
if (typeof input === "string") {
|
||||||
const parsedURL = new URL(input, baseURL);
|
const parsedURL = new URL(input, baseURL);
|
||||||
request = newInnerRequest(
|
request = newInnerRequest(
|
||||||
() => "GET",
|
"GET",
|
||||||
parsedURL.href,
|
parsedURL.href,
|
||||||
() => [],
|
() => [],
|
||||||
null,
|
null,
|
||||||
|
@ -455,14 +429,9 @@ class Request {
|
||||||
if (this[_method]) {
|
if (this[_method]) {
|
||||||
return this[_method];
|
return this[_method];
|
||||||
}
|
}
|
||||||
if (this[_flash]) {
|
|
||||||
this[_method] = this[_flash].methodCb();
|
|
||||||
return this[_method];
|
|
||||||
} else {
|
|
||||||
this[_method] = this[_request].method;
|
this[_method] = this[_request].method;
|
||||||
return this[_method];
|
return this[_method];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
get url() {
|
get url() {
|
||||||
webidl.assertBranded(this, RequestPrototype);
|
webidl.assertBranded(this, RequestPrototype);
|
||||||
|
@ -470,14 +439,9 @@ class Request {
|
||||||
return this[_url];
|
return this[_url];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this[_flash]) {
|
|
||||||
this[_url] = this[_flash].urlCb();
|
|
||||||
return this[_url];
|
|
||||||
} else {
|
|
||||||
this[_url] = this[_request].url();
|
this[_url] = this[_request].url();
|
||||||
return this[_url];
|
return this[_url];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
get headers() {
|
get headers() {
|
||||||
webidl.assertBranded(this, RequestPrototype);
|
webidl.assertBranded(this, RequestPrototype);
|
||||||
|
@ -486,9 +450,6 @@ class Request {
|
||||||
|
|
||||||
get redirect() {
|
get redirect() {
|
||||||
webidl.assertBranded(this, RequestPrototype);
|
webidl.assertBranded(this, RequestPrototype);
|
||||||
if (this[_flash]) {
|
|
||||||
return this[_flash].redirectMode;
|
|
||||||
}
|
|
||||||
return this[_request].redirectMode;
|
return this[_request].redirectMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,32 +463,17 @@ class Request {
|
||||||
if (this[_body] && this[_body].unusable()) {
|
if (this[_body] && this[_body].unusable()) {
|
||||||
throw new TypeError("Body is unusable.");
|
throw new TypeError("Body is unusable.");
|
||||||
}
|
}
|
||||||
let newReq;
|
const newReq = cloneInnerRequest(this[_request]);
|
||||||
if (this[_flash]) {
|
|
||||||
newReq = cloneInnerRequest(this[_flash], false, true);
|
|
||||||
} else {
|
|
||||||
newReq = cloneInnerRequest(this[_request]);
|
|
||||||
}
|
|
||||||
const newSignal = abortSignal.newSignal();
|
const newSignal = abortSignal.newSignal();
|
||||||
|
|
||||||
if (this[_signal]) {
|
if (this[_signal]) {
|
||||||
abortSignal.follow(newSignal, this[_signal]);
|
abortSignal.follow(newSignal, this[_signal]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this[_flash]) {
|
|
||||||
return fromInnerRequest(
|
return fromInnerRequest(
|
||||||
newReq,
|
newReq,
|
||||||
newSignal,
|
newSignal,
|
||||||
guardFromHeaders(this[_headers]),
|
guardFromHeaders(this[_headers]),
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fromInnerRequest(
|
|
||||||
newReq,
|
|
||||||
newSignal,
|
|
||||||
guardFromHeaders(this[_headers]),
|
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,58 +552,17 @@ function toInnerRequest(request) {
|
||||||
* @param {InnerRequest} inner
|
* @param {InnerRequest} inner
|
||||||
* @param {AbortSignal} signal
|
* @param {AbortSignal} signal
|
||||||
* @param {"request" | "immutable" | "request-no-cors" | "response" | "none"} guard
|
* @param {"request" | "immutable" | "request-no-cors" | "response" | "none"} guard
|
||||||
* @param {boolean} flash
|
|
||||||
* @returns {Request}
|
* @returns {Request}
|
||||||
*/
|
*/
|
||||||
function fromInnerRequest(inner, signal, guard, flash) {
|
function fromInnerRequest(inner, signal, guard) {
|
||||||
const request = webidl.createBranded(Request);
|
const request = webidl.createBranded(Request);
|
||||||
if (flash) {
|
|
||||||
request[_flash] = inner;
|
|
||||||
} else {
|
|
||||||
request[_request] = inner;
|
request[_request] = inner;
|
||||||
}
|
|
||||||
request[_signal] = signal;
|
request[_signal] = signal;
|
||||||
request[_getHeaders] = flash
|
request[_getHeaders] = () => headersFromHeaderList(inner.headerList, guard);
|
||||||
? () => 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");
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
_flash,
|
|
||||||
fromFlashRequest,
|
|
||||||
fromInnerRequest,
|
fromInnerRequest,
|
||||||
newInnerRequest,
|
newInnerRequest,
|
||||||
processUrlList,
|
processUrlList,
|
||||||
|
|
1
ext/fetch/internal.d.ts
vendored
1
ext/fetch/internal.d.ts
vendored
|
@ -78,7 +78,6 @@ declare module "ext:deno_fetch/26_fetch.js" {
|
||||||
| "response"
|
| "response"
|
||||||
| "none",
|
| "none",
|
||||||
skipBody: boolean,
|
skipBody: boolean,
|
||||||
flash: boolean,
|
|
||||||
): Request;
|
): Request;
|
||||||
function redirectStatus(status: number): boolean;
|
function redirectStatus(status: number): boolean;
|
||||||
function nullBodyStatus(status: number): boolean;
|
function nullBodyStatus(status: number): boolean;
|
||||||
|
|
|
@ -14,7 +14,6 @@ import {
|
||||||
toInnerResponse,
|
toInnerResponse,
|
||||||
} from "ext:deno_fetch/23_response.js";
|
} from "ext:deno_fetch/23_response.js";
|
||||||
import {
|
import {
|
||||||
_flash,
|
|
||||||
fromInnerRequest,
|
fromInnerRequest,
|
||||||
newInnerRequest,
|
newInnerRequest,
|
||||||
toInnerRequest,
|
toInnerRequest,
|
||||||
|
@ -134,7 +133,7 @@ class HttpConn {
|
||||||
}
|
}
|
||||||
|
|
||||||
const innerRequest = newInnerRequest(
|
const innerRequest = newInnerRequest(
|
||||||
() => method,
|
method,
|
||||||
url,
|
url,
|
||||||
() => ops.op_http_headers(streamRid),
|
() => ops.op_http_headers(streamRid),
|
||||||
body !== null ? new InnerBody(body) : null,
|
body !== null ? new InnerBody(body) : null,
|
||||||
|
@ -467,12 +466,6 @@ function upgradeWebSocket(request, options = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function upgradeHttp(req) {
|
function upgradeHttp(req) {
|
||||||
if (req[_flash]) {
|
|
||||||
throw new TypeError(
|
|
||||||
"Flash requests can not be upgraded with `upgradeHttp`. Use `upgradeHttpRaw` instead.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
req[_deferred] = new Deferred();
|
req[_deferred] = new Deferred();
|
||||||
return req[_deferred].promise;
|
return req[_deferred].promise;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue