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
Test the default Content-Type headers of Request and Response objects #29554
Conversation
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)"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MIME types in Blob
s 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 Blob
s 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.
There was a problem hiding this comment.
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}`, |
There was a problem hiding this comment.
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 😑
There was a problem hiding this comment.
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)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.
No description provided.