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

Fix overrideMimeType() again #174

Merged
merged 3 commits into from
Apr 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 40 additions & 29 deletions xhr.bs
Original file line number Diff line number Diff line change
@@ -495,6 +495,7 @@ methods, when invoked, must run these steps:
<a>network error</a>.
<li><p>Set <a>received bytes</a> to the empty byte sequence.
<li><p>Set <a>response object</a> to null.
<li><p>Set <a>override MIME type</a> to null.
</ul>

<li>
@@ -1299,19 +1300,32 @@ transfer-encoding: chunked</code></pre>
<li><p>Return <var>mimeType</var>.
</ol>

<p>The <dfn id=override-mime-type>override MIME type</dfn> is initially null and can get a value if
{{overrideMimeType()}} is invoked. <dfn id=final-mime-type>Final MIME type</dfn> is the
<p>The <dfn id=override-mime-type>override MIME type</dfn> is initially null and can get a value
when {{overrideMimeType()}} is invoked. The <dfn id=final-mime-type>final MIME type</dfn> is the
<a>override MIME type</a> unless that is null in which case it is the <a>response MIME type</a>.

<p>The <dfn id=response-charset>response charset</dfn> is the value of
the <code>charset</code> parameter of the `<code>Content-Type</code>` header
or null if there was no `<code>charset</code>` parameter or the header could
not be parsed or was omitted. The
<dfn id=override-charset>override charset</dfn> is initially null and
can get a value if <a><code>overrideMimeType()</code></a> is invoked.
<dfn id=final-charset>Final charset</dfn> is the
<a>override charset</a> unless
that is null in which case it is the <a>response charset</a>.
<p>The <dfn id=final-charset>final charset</dfn> is the return value of these steps:

<ol>
<li><p>Let <var>label</var> be null.

<li><p>If <a>response MIME type</a>'s <a for="MIME type">parameters</a>["<code>charset</code>"]
<a for=map>exists</a>, then set <var>label</var> to it.

<li><p>If <a>override MIME type</a>'s <a for="MIME type">parameters</a>["<code>charset</code>"]
<a for=map>exists</a>, then set <var>label</var> to it.

<li><p>If <var>label</var> is null, then return null.

<li><p>Let <var>encoding</var> be the result of <a>getting an encoding</a> from <var>label</var>.

<li><p>If <var>encoding</var> is failure, then return null.

<li><p>Return <var>encoding</var>.
</ol>

<p class=note>The above steps intentionally do not use the <a>final MIME type</a> as it would yield
the wrong result.

<hr>

@@ -1336,7 +1350,7 @@ or null). Unless stated otherwise it is null.

<ol>
<li><p>Set <a>response object</a> to a new {{Blob}} object representing <a>received bytes</a> with
{{Blob/type}} <a>final MIME type</a>.
{{Blob/type}} set to the <a>final MIME type</a>.

<li><p>Return <a>response object</a>.
</ol>
@@ -1348,11 +1362,11 @@ or null). Unless stated otherwise it is null.
<li><p>If <a>response</a>'s
<a for=response>body</a> is null, then return null.

<li><p>If <a>final MIME type</a> is not an <a>HTML MIME type</a> or an <a>XML MIME type</a>, then
return null.
<li><p>If the <a>final MIME type</a> is not an <a>HTML MIME type</a> or an <a>XML MIME type</a>,
then return null.

<li>
<p>If {{XMLHttpRequest/responseType}} is the empty string and <a>final MIME type</a> is an
<p>If {{XMLHttpRequest/responseType}} is the empty string and the <a>final MIME type</a> is an
<a>HTML MIME type</a>, then return null.

<p class=note>This is restricted to
@@ -1361,7 +1375,7 @@ or null). Unless stated otherwise it is null.
content.

<li>
<p>If <a>final MIME type</a> is an <a>HTML MIME type</a>, then run these substeps:
<p>If the <a>final MIME type</a> is an <a>HTML MIME type</a>, then:

<ol>
<li><p>Let <var>charset</var> be the <a>final charset</a>.
@@ -1406,7 +1420,7 @@ or null). Unless stated otherwise it is null.
<a for=Document>encoding</a> to
<var>charset</var>.

<li><p>Set <var>document</var>'s <a>content type</a> to <a>final MIME type</a>.
<li><p>Set <var>document</var>'s <a>content type</a> to the <a>final MIME type</a>.

<li><p>Set <var>document</var>'s
<a for=Document>URL</a> to
@@ -1445,7 +1459,7 @@ or null). Unless stated otherwise it is null.
<li><p>Let <var>charset</var> be the <a>final charset</a>.

<li>
<p>If {{XMLHttpRequest/responseType}} is the empty string, <var>charset</var> is null, and
<p>If {{XMLHttpRequest/responseType}} is the empty string, <var>charset</var> is null, and the
<a>final MIME type</a> is an <a>XML MIME type</a>, then use the rules set forth in the XML
specifications to determine the encoding. Let <var>charset</var> be the determined encoding.
[[!XML]] [[!XMLNS]]
@@ -1474,28 +1488,25 @@ resources using <a>utf-8</a>.
<dl class=domintro>
<dt><code><var>client</var> . <a method for=XMLHttpRequest>overrideMimeType(<var>mime</var>)</a></code>
<dd>
<p>Acts as if the `<code>Content-Type</code>` header for <a>response</a> is <var>mime</var>.
<p>Acts as if the `<code>Content-Type</code>` header value for <a>response</a> is <var>mime</var>.
(It does not actually change the header though.)

<p>Throws an "{{InvalidStateError!!exception}}" {{DOMException}} if <a>state</a> is <i>loading</i>
or <i>done</i>.
</dl>

<p>The
<dfn method for=XMLHttpRequest><code>overrideMimeType(<var>mime</var>)</code></dfn>
method must run these steps:
<p>The <dfn method for=XMLHttpRequest><code>overrideMimeType(<var>mime</var>)</code></dfn> method,
when invoked, must run these steps:

<ol>
<li><p>If <a>state</a> is <i>loading</i> or <i>done</i>, then <a>throw</a> an
"{{InvalidStateError!!exception}}" {{DOMException}}.

<li><p>Set <a>override MIME type</a> to `<code>application/octet-stream</code>`.

<li><p>If <var>mime</var> is a <a>parsable MIME type</a>, then set <a>override MIME type</a> to its
<a>MIME type portion</a>.
<!-- XXX Ignore string to byte sequence conversion issues until some point in the future -->
<li><p>Set <a>override MIME type</a> to the result of <a lt="parse a MIME type">parsing</a>
<var>mime</var>.
Copy link
Member

Choose a reason for hiding this comment

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

This no longer throws out all the parameters. I think that is observable using e.g. a Blob response's type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's intentional (and tested).


<li><p>If <a>override MIME type</a> has a `<code>charset</code>` parameter, then set
<a>override charset</a> to its value.
<li><p>If <a>override MIME type</a> is failure, then set <a>override MIME type</a> to
<code>application/octet-stream</code>.
</ol>