Define Content-Type manipulation in terms of MIME Sniffing#176
Define Content-Type manipulation in terms of MIME Sniffing#176
Conversation
|
|
|
It also seems like a few combinations might not be tested well here. Such as when mimeType or encoding is null. |
|
|
||
| <!-- 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: |
There was a problem hiding this comment.
What if mimeType is null but author request headers does not contain a Content-Type header?
| <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>. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| <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>. |
There was a problem hiding this comment.
This (and serialized) isn't linking in the previous but probably that's because this is an old PR. Worth confirming before merging.
|
|
||
| <li> | ||
| <p>If <var>mimeTypeRecord</var> is not failure and | ||
| <var>mimeTypeRecord</var>["<code>charset</code>"] is not nothing, then: |
There was a problem hiding this comment.
This should be referencing the record's parameters, right?
And using "exists" for ordered maps, not "is not nothing"
Note that this also replaces "utf-8" with "UTF-8" and no longer preserves duplicate parameters. Tests: web-platform-tests/wpt#8422.
5079f6f to
bfc49d8
Compare
|
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. |
|
For commit message: fixes #188. |
Needed for whatwg/xhr#176.
Needed for whatwg/xhr#176.
domenic
left a comment
There was a problem hiding this comment.
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.
| <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>. |
There was a problem hiding this comment.
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.
|
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. |
|
I mean it seems like if you have "contains" you really should have an analogous "get". It should just return the byte sequence. |
|
I'm not quite sure how it'd make sense to test all those MIME types here? There's far less observable bits. |
|
@domenic but that's likely wrong given multiple headers and such, no? |
|
I'm not sure why it would be. You already have an analogous operation you are using:
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 |
|
@domenic that phrasing works here since I'll see about reusing the MIME type parsing tests, perhaps at least the navigable ones can be used here (with an encoding). |
|
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.) |
|
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. |
|
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. |
…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
…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
…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
…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
…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
Note that this also replaces "utf-8" with "UTF-8" and no longer preserves duplicate parameters.
Tests: web-platform-tests/wpt#8422.
Preview | Diff