spec
spec copied to clipboard
[wasm-web-api-1] Don't use fetch's "extract a MIME type"
As I was looking into refactoring some code in Deno's implementation of the wasm web APIs, I noticed that the spec calls into fetch's "extract a MIME type" algorithm, and treats its return value as if it were a string, when it is in fact a MIME type record. The WHATWG MIME sniffing spec defines an algorithm to serialize a MIME type record, but that doesn't work in this case since the parsing and serialization roundtrip normalizes application/wasm;
to application/wasm
(see also #1140).
Looking further, it seems like when this reference to "extract a MIME type" was introduced, that algorithm did return a string. However, we still run into a type error because it treats the return value of "extract header list values" as a string, even though it is an array.
So instead I looked at the code to see what browsers are actually doing. Chromium, WebKit and Deno all replace steps 2.2 and 2.3 of "compile a potential WebAssembly response" with:
- Let mimeType be the result of getting
`Content-Type`
from response's header list. - If mimeType is null, or if it is not a byte-case-insensitive match for
`application/wasm`
, reject returnValue with aTypeError
and abort these substeps.
I'm not sure whether Firefox does this or not, because the handling of responses for the wasm streaming APIs happens inside network code, and I couldn't easily follow what it does.
cc @annevk
Gecko code seems to be here: https://searchfox.org/mozilla-central/rev/f8db81665dc2833fff09dc7eef200539ac1fd351/dom/fetch/Fetch.cpp#1344 https://searchfox.org/mozilla-central/rev/f8db81665dc2833fff09dc7eef200539ac1fd351/dom/fetch/FetchUtil.cpp#674
We'd definitely need some tests for this
In https://github.com/WebAssembly/design/pull/991 there was a decision that application/wasm;
has to reject. There are tests for this in Gecko, but I'm not sure if there are web-platform-tests as well.
Fetch changed in https://github.com/whatwg/fetch/pull/831.
The simplest change here would be to do as @andreubotella suggests. It might be worth considering if we should align application/wasm
with how we handle other MIME types, but that should be a separate decision.
There's https://github.com/web-platform-tests/wpt/blob/master/wasm/webapi/contenttype.any.js, but it doesn't test zero or multiple Content-Type
headers.
It might be worth considering if we should align
application/wasm
with how we handle other MIME types, but that should be a separate decision.
I think #1140 would be the appropriate issue to discuss that.
Let's dupe this into #1138 (which was fixed).