whatwg / fetch

Fetch Standard

Home Page:https://fetch.spec.whatwg.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

interop: content-type for blob fetch with invalid type

dlrobertson opened this issue · comments

From File API - Blob.type:

[...] the type of a Blob as an ASCII-encoded string in lower case, such that when it is converted to a byte sequence, it is a parsable MIME type, or the empty string – 0 bytes – if the type cannot be determined.

Based on my reading of this, I'd expect that a fetch of blob created with an invalid mime type for type would result in the Content-Type set to the empty string (similar to a blob created without a input type #1436).

Given the following test:

diff --git a/fetch/api/basic/scheme-blob.sub.any.js b/fetch/api/basic/scheme-blob.sub.any.js
index a6059ea93d..8afdc033c9 100644
--- a/fetch/api/basic/scheme-blob.sub.any.js
+++ b/fetch/api/basic/scheme-blob.sub.any.js
@@ -57,6 +57,10 @@ let empty_data_blob = new Blob([], {type: "text/plain"});
 checkFetchResponse(URL.createObjectURL(empty_data_blob), "", "text/plain", 0,
                   "Fetching URL.createObjectURL(empty_data_blob) is OK");

+let invalid_type_blob = new Blob([], {type: "invalid"});
+checkFetchResponse(URL.createObjectURL(invalid_type_blob), "", "", 0,
+                  "Fetching URL.createObjectURL(invalid_type_blob) is OK");
+
 promise_test(function(test) {
   return fetch("/images/blue.png").then(function(resp) {
     return resp.arrayBuffer();

I get the following results:

Browser Content-Type
Firefox "application/x-unknown-content-type"
Chrome "invalid"
Safari "invalid"

Yeah, I think the correct long term answer here is that blobs have an internal type slot that is either a MIME type or null. When Fetch serializes that it either gets a valid MIME type or the empty byte sequence.

(At least, I think elsewhere we already settled on using the empty byte sequence as Content-Type value. And while that's not great, it's also not the worst. Certainly much better than invalid.)