mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
feat(etc/fetch): Support WebAssembly.instantiateStreaming
for file fetches (#12901)
Fetching of local files, added in #12545, returns a response with no headers, including the `Content-Type` header. This currently makes it not work with the WebAssembly streaming APIs, which require the response to have a content type of `application/wasm`. Since the only way to obtain a `Response` object with a non-empty `url` field is via `fetch()`, this change changes the content type requirement to only apply to responses whose url has the `file:` scheme.
This commit is contained in:
parent
6a780543a4
commit
d763633781
2 changed files with 25 additions and 6 deletions
|
@ -37,6 +37,7 @@
|
|||
PromisePrototypeThen,
|
||||
PromisePrototypeCatch,
|
||||
String,
|
||||
StringPrototypeStartsWith,
|
||||
StringPrototypeToLowerCase,
|
||||
TypedArrayPrototypeSubarray,
|
||||
TypeError,
|
||||
|
@ -498,12 +499,16 @@
|
|||
// The spec is ambiguous here, see
|
||||
// https://github.com/WebAssembly/spec/issues/1138. The WPT tests
|
||||
// expect the raw value of the Content-Type attribute lowercased.
|
||||
const contentType = res.headers.get("Content-Type");
|
||||
if (
|
||||
typeof contentType !== "string" ||
|
||||
StringPrototypeToLowerCase(contentType) !== "application/wasm"
|
||||
) {
|
||||
throw new TypeError("Invalid WebAssembly content type.");
|
||||
// We ignore this for file:// because file fetches don't have a
|
||||
// Content-Type.
|
||||
if (!StringPrototypeStartsWith(res.url, "file://")) {
|
||||
const contentType = res.headers.get("Content-Type");
|
||||
if (
|
||||
typeof contentType !== "string" ||
|
||||
StringPrototypeToLowerCase(contentType) !== "application/wasm"
|
||||
) {
|
||||
throw new TypeError("Invalid WebAssembly content type.");
|
||||
}
|
||||
}
|
||||
|
||||
// 2.5.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue