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

Test the default Content-Type headers of Request and Response objects #29554

Merged
merged 1 commit into from Jul 30, 2021
Merged

Test the default Content-Type headers of Request and Response objects #29554

merged 1 commit into from Jul 30, 2021

Conversation

andreubotella
Copy link
Member

No description provided.

const blob = new Blob([], { type: "a/b; c=d" });
const request = requestFromBody(blob);
assert_equals(request.headers.get("Content-Type"), "a/b; c=d");
}, "Default Content-Type for Request with Blob body (set type)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test a non-canonicalized MIME type, e.g. Text/HTML;Charset="utf-8"? I can't remember whether this should canonicalize (as text/html;charset=utf-8) or be left as-is.

Similarly testing an invalid-but-ASCII MIME type (e.g. "foo") and a Unicode MIME type (e.g. "😋/😁") would be worthwhile IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIME types in Blobs are known to be broken, see w3c/FileAPI#43 and in particular w3c/FileAPI#43 (comment). The general consensus in that issue seems to be that Blobs should parse and serialize the MIME type, and some tests were added in #7764, but the spec hasn't been changed yet. So I'd rather not add new tests that contradict the ones from #7764.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

const boundary = (await request.text()).split("\r\n")[0].slice(2);
assert_equals(
request.headers.get("Content-Type"),
`multipart/form-data; boundary=${boundary}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super-awesome that the spec mandates a non-canonical MIME type here (with the space) which is inconsistent with the below two tests 😑

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See whatwg/fetch#422. I'm not sure what browsers did when Hixie introduced the boundary parameter to the spec in 2011, but now they're consistent.

const blob = new Blob([], { type: "a/b; c=d" });
const request = requestFromBody(blob);
assert_equals(request.headers.get("Content-Type"), "a/b; c=d");
}, "Default Content-Type for Request with Blob body (set type)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@andreubotella andreubotella merged commit 9dcc748 into web-platform-tests:master Jul 30, 2021
@andreubotella andreubotella deleted the response-request-default-mime branch July 30, 2021 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants