Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interop: content-type for blob fetch with invalid type #1693

Open
dlrobertson opened this issue Aug 7, 2023 · 2 comments
Open

interop: content-type for blob fetch with invalid type #1693

dlrobertson opened this issue Aug 7, 2023 · 2 comments

Comments

@dlrobertson
Copy link
Member

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"
@mkruisselbrink
Copy link
Collaborator

Related w3c/FileAPI#43

@annevk
Copy link
Member

annevk commented Aug 24, 2023

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants