summaryrefslogtreecommitdiff
path: root/ext/fetch/23_request.js
diff options
context:
space:
mode:
authorAndreu Botella <abb@randomunok.com>2021-09-08 11:29:21 +0200
committerGitHub <noreply@github.com>2021-09-08 11:29:21 +0200
commit1563088f060b1f1d4826bb3a6d4120b276a4e15f (patch)
treeff8b406511f0e7322a55e32d5272298ea4a061b5 /ext/fetch/23_request.js
parente07f28d301b990ebf534cbb8d5fa9f507475c89f (diff)
fix: a `Request` whose URL is a revoked blob URL should still fetch (#11947)
In the spec, a URL record has an associated "blob URL entry", which for `blob:` URLs is populated during parsing to contain a reference to the `Blob` object that backs that object URL. It is this blob URL entry that the `fetch` API uses to resolve an object URL. Therefore, since the `Request` constructor parses URL inputs, it will have an associated blob URL entry which will be used when fetching, even if the object URL has been revoked since the construction of the `Request` object. (The `Request` constructor takes the URL as a string and parses it, so the object URL must be live at the time it is called.) This PR adds a new `blobFromObjectUrl` JS function (backed by a new `op_blob_from_object_url` op) that, if the URL is a valid object URL, returns a new `Blob` object whose parts are references to the same Rust `BlobPart`s used by the original `Blob` object. It uses this function to add a new `blobUrlEntry` field to inner requests, which will be `null` or such a `Blob`, and then uses `Blob.prototype.stream()` as the response's body. As a result of this, the `blob:` URL resolution from `op_fetch` is now useless, and has been removed.
Diffstat (limited to 'ext/fetch/23_request.js')
-rw-r--r--ext/fetch/23_request.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js
index 1372125c1..36c63db2a 100644
--- a/ext/fetch/23_request.js
+++ b/ext/fetch/23_request.js
@@ -19,6 +19,7 @@
const { mixinBody, extractBody } = window.__bootstrap.fetchBody;
const { getLocationHref } = window.__bootstrap.location;
const mimesniff = window.__bootstrap.mimesniff;
+ const { blobFromObjectUrl } = window.__bootstrap.file;
const {
headersFromHeaderList,
headerListFromHeaders,
@@ -59,6 +60,7 @@
* @property {number} redirectCount
* @property {string[]} urlList
* @property {number | null} clientRid NOTE: non standard extension for `Deno.HttpClient`.
+ * @property {Blob | null} blobUrlEntry
*/
const defaultInnerRequest = {
@@ -81,11 +83,16 @@
* @returns
*/
function newInnerRequest(method, url, headerList = [], body = null) {
+ let blobUrlEntry = null;
+ if (url.startsWith("blob:")) {
+ blobUrlEntry = blobFromObjectUrl(url);
+ }
return {
method: method,
headerList,
body,
urlList: [url],
+ blobUrlEntry,
...defaultInnerRequest,
};
}
@@ -118,6 +125,7 @@
redirectCount: request.redirectCount,
urlList: request.urlList,
clientRid: request.clientRid,
+ blobUrlEntry: request.blobUrlEntry,
};
}