Skip to content

Define Content-Type manipulation in terms of MIME Sniffing#176

Merged
annevk merged 4 commits intomasterfrom
annevk/content-type-manipulation
Apr 16, 2018
Merged

Define Content-Type manipulation in terms of MIME Sniffing#176
annevk merged 4 commits intomasterfrom
annevk/content-type-manipulation

Conversation

@annevk
Copy link
Copy Markdown
Member

@annevk annevk commented Dec 5, 2017

Note that this also replaces "utf-8" with "UTF-8" and no longer preserves duplicate parameters.

Tests: web-platform-tests/wpt#8422.


Preview | Diff

@annevk
Copy link
Copy Markdown
Member Author

annevk commented Dec 5, 2017

Note that this builds on whatwg/mimesniff#36 which has not landed yet.

@annevk
Copy link
Copy Markdown
Member Author

annevk commented Dec 5, 2017

It also seems like a few combinations might not be tested well here. Such as when mimeType or encoding is null.

domenic
domenic previously requested changes Feb 5, 2018
Comment thread xhr.bs Outdated

<!-- reminder: if we ever change this to always include charset it has
to be included as the first parameter for compatibility reasons -->
<p>Otherwise, if <var>encoding</var> is non-null, run these steps:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if mimeType is null but author request headers does not contain a Content-Type header?

Comment thread xhr.bs
<ol>
<li><p>Let <var>value</var> be the <a for=header>value</a> of the <a>header</a> whose
<a for=header>name</a> is a <a>byte-case-insensitive</a> match for `<code>Content-Type</code>` in
<a>author request headers</a>.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm surprised header list doesn't have a "get" operation that does the byte-case-insensitive part for you. It has so many of the other operations you'd expect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like to still get this fixed because it contrasts with "contains" very strongly. Reading without clicking links might lead one to say that this operation is byte-case-insensitive but the above check is case-sensitive.

Comment thread xhr.bs Outdated
<a>author request headers</a>.

<li><p>Let <var>mimeTypeRecord</var> be <var>value</var>,
<a for="parse a MIME type from bytes">parsed</a>.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This (and serialized) isn't linking in the previous but probably that's because this is an old PR. Worth confirming before merging.

Comment thread xhr.bs Outdated

<li>
<p>If <var>mimeTypeRecord</var> is not failure and
<var>mimeTypeRecord</var>["<code>charset</code>"] is not nothing, then:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be referencing the record's parameters, right?

And using "exists" for ordered maps, not "is not nothing"

annevk added 2 commits April 10, 2018 14:28
Note that this also replaces "utf-8" with "UTF-8" and no longer preserves duplicate parameters.

Tests: web-platform-tests/wpt#8422.
@annevk annevk force-pushed the annevk/content-type-manipulation branch from 5079f6f to bfc49d8 Compare April 10, 2018 12:35
@annevk annevk requested a review from domenic April 10, 2018 12:36
@annevk
Copy link
Copy Markdown
Member Author

annevk commented Apr 10, 2018

Thanks for the review and sorry for the slow turnaround. Really want to start closing all these minor MIME type issues everywhere, though I'm sure it'll take longer than anticipated.

annevk added a commit to web-platform-tests/wpt that referenced this pull request Apr 10, 2018
@annevk
Copy link
Copy Markdown
Member Author

annevk commented Apr 10, 2018

For commit message: fixes #188.

annevk added a commit to whatwg/mimesniff that referenced this pull request Apr 10, 2018
annevk added a commit to whatwg/mimesniff that referenced this pull request Apr 10, 2018
Copy link
Copy Markdown
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Looks pretty good although as noted I really think we should add "get" to headers list, preferably before merging this or at least very soon after.

I still find this algorithm a bit confusing to try to follow by hand but I'll noodle on whether we can do anything better in a follow-up.

For tests it'd be worth testing everything in the MIME types JSON file, I think, to make sure that we're using the same parser here as everywhere else on the platform.

Comment thread xhr.bs
<ol>
<li><p>Let <var>value</var> be the <a for=header>value</a> of the <a>header</a> whose
<a for=header>name</a> is a <a>byte-case-insensitive</a> match for `<code>Content-Type</code>` in
<a>author request headers</a>.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like to still get this fixed because it contrasts with "contains" very strongly. Reading without clicking links might lead one to say that this operation is byte-case-insensitive but the above check is case-sensitive.

@annevk
Copy link
Copy Markdown
Member Author

annevk commented Apr 10, 2018

Getting header values is a can of worms. Currently Fetch only has accessors that also parse and I'm really not sure what the right approach is here yet.

@domenic
Copy link
Copy Markdown
Member

domenic commented Apr 10, 2018

I mean it seems like if you have "contains" you really should have an analogous "get". It should just return the byte sequence.

@annevk
Copy link
Copy Markdown
Member Author

annevk commented Apr 10, 2018

I'm not quite sure how it'd make sense to test all those MIME types here? There's far less observable bits.

@annevk
Copy link
Copy Markdown
Member Author

annevk commented Apr 10, 2018

@domenic but that's likely wrong given multiple headers and such, no?

@domenic
Copy link
Copy Markdown
Member

domenic commented Apr 10, 2018

I'm not sure why it would be. You already have an analogous operation you are using:

Let value be the value of the header whose name is a byte-case-insensitive match for Content-Type in author request headers.

What's wrong with just defining it that way?


As for testing all the MIME types, I was thinking, set Content-Type/the value from the JSON file for every value in the JSON file. Then, check that the resulting Content-Type the server sees is the same as the output from the JSON file, except all charset parameters must be changed to UTF-8 (so do something like s/charset=[A-Z-]+/charset=UTF-8).

@annevk
Copy link
Copy Markdown
Member Author

annevk commented Apr 10, 2018

@domenic that phrasing works here since setRequestHeader() aggressively combines, but a definition for "header list" would need to take other scenarios into account.

I'll see about reusing the MIME type parsing tests, perhaps at least the navigable ones can be used here (with an encoding).

@domenic
Copy link
Copy Markdown
Member

domenic commented Apr 10, 2018

You could also use all the others plus a null body (or any non-Document non-string body) to make sure they aren't being parsed, i.e. are just being passed through without changes.

@annevk
Copy link
Copy Markdown
Member Author

annevk commented Apr 11, 2018

You could also use all the others plus a null body (or any non-Document non-string body) to make sure they aren't being parsed, i.e. are just being passed through without changes.

It seems that can be confirmed with a single test (and I strongly suspect already is). (Edit: I had already written a test for this.)

@annevk
Copy link
Copy Markdown
Member Author

annevk commented Apr 11, 2018

I don't really see an easy way to reuse https://github.com/w3c/web-platform-tests/blob/master/mimesniff/mime-types/resources/mime-types.json here other than adding more fields to it. Otherwise there's a lot of post-processing of the kind you'd then object to. I think we should just go ahead here and maybe file that as follow-up if anyone is interested in doing the work.

@domenic
Copy link
Copy Markdown
Member

domenic commented Apr 11, 2018

That seems reasonable. I think it's the right strategy, but we don't want to burden spec maintainers with comprehensive tests and block all forward spec progress until they're done.

The reason I prefer being more comprehensive than a single test is that if a browser parses-then-reserializes using some XHR-specific parser, a single test might not catch a difference, depending on the algorithm.

@annevk annevk merged commit edc6f8f into master Apr 16, 2018
@annevk annevk deleted the annevk/content-type-manipulation branch April 16, 2018 09:51
annevk added a commit to web-platform-tests/wpt that referenced this pull request Apr 16, 2018
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Apr 26, 2018
…ng, a=testonly

Automatic update from web-platform-testsAdjust XMLHttpRequest Content-Type handling

See whatwg/xhr#176 and whatwg/mimesniff#36.
--

wpt-commits: 84e7972a0518fb57f39740143d4b63e79b14e9f4
wpt-pr: 8422
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 2, 2019
…ng, a=testonly

Automatic update from web-platform-testsAdjust XMLHttpRequest Content-Type handling

See whatwg/xhr#176 and whatwg/mimesniff#36.
--

wpt-commits: 84e7972a0518fb57f39740143d4b63e79b14e9f4
wpt-pr: 8422

UltraBlame original commit: be93580d93e3b6e94946124f06c188bc8daac745
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 3, 2019
…ng, a=testonly

Automatic update from web-platform-testsAdjust XMLHttpRequest Content-Type handling

See whatwg/xhr#176 and whatwg/mimesniff#36.
--

wpt-commits: 84e7972a0518fb57f39740143d4b63e79b14e9f4
wpt-pr: 8422

UltraBlame original commit: be93580d93e3b6e94946124f06c188bc8daac745
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 3, 2019
…ng, a=testonly

Automatic update from web-platform-testsAdjust XMLHttpRequest Content-Type handling

See whatwg/xhr#176 and whatwg/mimesniff#36.
--

wpt-commits: 84e7972a0518fb57f39740143d4b63e79b14e9f4
wpt-pr: 8422

UltraBlame original commit: be93580d93e3b6e94946124f06c188bc8daac745
bhearsum pushed a commit to mozilla-releng/staging-firefox that referenced this pull request May 1, 2025
…ng, a=testonly

Automatic update from web-platform-testsAdjust XMLHttpRequest Content-Type handling

See whatwg/xhr#176 and whatwg/mimesniff#36.
--

wpt-commits: 84e7972a0518fb57f39740143d4b63e79b14e9f4
wpt-pr: 8422
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants