Skip to content

Commit 121cee5

Browse files
authored
Fix overrideMimeType() again
This makes a number of changes: * Integrates with the new MIME Sniffing infrastructure. * Reset override MIME type when open() is invoked. * Actually make overriding the charset parameter work (setting override MIME type to the "MIME type portion" (now essence) as done previously would always erase it). * Use "get an encoding" (previously undefined) to convert from a label to an encoding. Tests: web-platform-tests/wpt#8449. Fixes #157.
1 parent edc6f8f commit 121cee5

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

xhr.bs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ methods, when invoked, must run these steps:
495495
<a>network error</a>.
496496
<li><p>Set <a>received bytes</a> to the empty byte sequence.
497497
<li><p>Set <a>response object</a> to null.
498+
<li><p>Set <a>override MIME type</a> to null.
498499
</ul>
499500

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

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

1306-
<p>The <dfn id=response-charset>response charset</dfn> is the value of
1307-
the <code>charset</code> parameter of the `<code>Content-Type</code>` header
1308-
or null if there was no `<code>charset</code>` parameter or the header could
1309-
not be parsed or was omitted. The
1310-
<dfn id=override-charset>override charset</dfn> is initially null and
1311-
can get a value if <a><code>overrideMimeType()</code></a> is invoked.
1312-
<dfn id=final-charset>Final charset</dfn> is the
1313-
<a>override charset</a> unless
1314-
that is null in which case it is the <a>response charset</a>.
1307+
<p>The <dfn id=final-charset>final charset</dfn> is the return value of these steps:
1308+
1309+
<ol>
1310+
<li><p>Let <var>label</var> be null.
1311+
1312+
<li><p>If <a>response MIME type</a>'s <a for="MIME type">parameters</a>["<code>charset</code>"]
1313+
<a for=map>exists</a>, then set <var>label</var> to it.
1314+
1315+
<li><p>If <a>override MIME type</a>'s <a for="MIME type">parameters</a>["<code>charset</code>"]
1316+
<a for=map>exists</a>, then set <var>label</var> to it.
1317+
1318+
<li><p>If <var>label</var> is null, then return null.
1319+
1320+
<li><p>Let <var>encoding</var> be the result of <a>getting an encoding</a> from <var>label</var>.
1321+
1322+
<li><p>If <var>encoding</var> is failure, then return null.
1323+
1324+
<li><p>Return <var>encoding</var>.
1325+
</ol>
1326+
1327+
<p class=note>The above steps intentionally do not use the <a>final MIME type</a> as it would yield
1328+
the wrong result.
13151329

13161330
<hr>
13171331

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

13371351
<ol>
13381352
<li><p>Set <a>response object</a> to a new {{Blob}} object representing <a>received bytes</a> with
1339-
{{Blob/type}} <a>final MIME type</a>.
1353+
{{Blob/type}} set to the <a>final MIME type</a>.
13401354

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

1351-
<li><p>If <a>final MIME type</a> is not an <a>HTML MIME type</a> or an <a>XML MIME type</a>, then
1352-
return null.
1365+
<li><p>If the <a>final MIME type</a> is not an <a>HTML MIME type</a> or an <a>XML MIME type</a>,
1366+
then return null.
13531367

13541368
<li>
1355-
<p>If {{XMLHttpRequest/responseType}} is the empty string and <a>final MIME type</a> is an
1369+
<p>If {{XMLHttpRequest/responseType}} is the empty string and the <a>final MIME type</a> is an
13561370
<a>HTML MIME type</a>, then return null.
13571371

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

13631377
<li>
1364-
<p>If <a>final MIME type</a> is an <a>HTML MIME type</a>, then run these substeps:
1378+
<p>If the <a>final MIME type</a> is an <a>HTML MIME type</a>, then:
13651379

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

1409-
<li><p>Set <var>document</var>'s <a>content type</a> to <a>final MIME type</a>.
1423+
<li><p>Set <var>document</var>'s <a>content type</a> to the <a>final MIME type</a>.
14101424

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

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

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

1483-
<p>The
1484-
<dfn method for=XMLHttpRequest><code>overrideMimeType(<var>mime</var>)</code></dfn>
1485-
method must run these steps:
1498+
<p>The <dfn method for=XMLHttpRequest><code>overrideMimeType(<var>mime</var>)</code></dfn> method,
1499+
when invoked, must run these steps:
14861500

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

1491-
<li><p>Set <a>override MIME type</a> to `<code>application/octet-stream</code>`.
1492-
1493-
<li><p>If <var>mime</var> is a <a>parsable MIME type</a>, then set <a>override MIME type</a> to its
1494-
<a>MIME type portion</a>.
1495-
<!-- XXX Ignore string to byte sequence conversion issues until some point in the future -->
1505+
<li><p>Set <a>override MIME type</a> to the result of <a lt="parse a MIME type">parsing</a>
1506+
<var>mime</var>.
14961507

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

15011512

0 commit comments

Comments
 (0)