From 52080669d9f663c837a630056e034383be253400 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 4 Dec 2017 16:26:28 +0100 Subject: [PATCH 1/3] Fix overrideMimeType() again 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. Tests: https://github.com/w3c/web-platform-tests/pull/8449. --- xhr.bs | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/xhr.bs b/xhr.bs index a0b11a3..3848a94 100644 --- a/xhr.bs +++ b/xhr.bs @@ -495,6 +495,7 @@ methods, when invoked, must run these steps: network error.
  • Set received bytes to the empty byte sequence.

  • Set response object to null. +

  • Set override MIME type to null.

  • @@ -1299,19 +1300,24 @@ transfer-encoding: chunked
  • Return mimeType. -

    The override MIME type is initially null and can get a value if -{{overrideMimeType()}} is invoked. Final MIME type is the +

    The override MIME type is initially null and can get a value +when {{overrideMimeType()}} is invoked. Final MIME type is the override MIME type unless that is null in which case it is the response MIME type. -

    The response charset is the value of -the charset parameter of the `Content-Type` header -or null if there was no `charset` parameter or the header could -not be parsed or was omitted. The -override charset is initially null and -can get a value if overrideMimeType() is invoked. -Final charset is the -override charset unless -that is null in which case it is the response charset. +

    Final charset is the return value of these steps: + +

      +
    1. If override MIME type's parameters["charset"] is + not nothing, then return it. + +

    2. If response MIME type's parameters["charset"] is + not nothing, then return it. + +

    3. Return null. +

    + +

    The above steps intentionally do not use final MIME type as it would yield the +wrong result.


    @@ -1474,28 +1480,26 @@ resources using utf-8.
    client . overrideMimeType(mime)
    -

    Acts as if the `Content-Type` header for response is mime. +

    Acts as if the `Content-Type` header value for response is mime. + (It does not actually change the header though.)

    Throws an "{{InvalidStateError!!exception}}" {{DOMException}} if state is loading or done.

    -

    The -overrideMimeType(mime) -method must run these steps: +

    The overrideMimeType(mime) method, +when invoked, must run these steps:

    1. If state is loading or done, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

    2. Set override MIME type to `application/octet-stream`. - -

    3. If mime is a parsable MIME type, then set override MIME type to its - MIME type portion. - +

    4. Set override MIME type to the result of parsing + mime. -

    5. If override MIME type has a `charset` parameter, then set - override charset to its value. +

    6. If override MIME type is failure, then set mimeTypeRecord to a new + MIME type whose type is "application" and + subtype is "octet-stream".

    From fb9ef1757f7bbcab36ad87aa2db2fc9b1e4a0d79 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 10 Apr 2018 19:36:01 +0200 Subject: [PATCH 2/3] address "get an encoding" --- xhr.bs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/xhr.bs b/xhr.bs index 3848a94..d5a7f97 100644 --- a/xhr.bs +++ b/xhr.bs @@ -1307,13 +1307,21 @@ when {{overrideMimeType()}} is invoked. Final MIME type<

    Final charset is the return value of these steps:

      -
    1. If override MIME type's parameters["charset"] is - not nothing, then return it. +

    2. Let label be null. -

    3. If response MIME type's parameters["charset"] is - not nothing, then return it. +

    4. If response MIME type's parameters["charset"] + exists, then set label to it. -

    5. Return null. +

    6. If override MIME type's parameters["charset"] + exists, then set label to it. + +

    7. If label is null, then return null. + +

    8. Let encoding be the result of getting an encoding from label. + +

    9. If encoding is failure, then return null. + +

    10. Return encoding.

    The above steps intentionally do not use final MIME type as it would yield the @@ -1497,7 +1505,7 @@ when invoked, must run these steps:

  • Set override MIME type to the result of parsing mime. -

  • If override MIME type is failure, then set mimeTypeRecord to a new +

  • If override MIME type is failure, then set override MIME type to a new MIME type whose type is "application" and subtype is "octet-stream". From 80dcbba720ead73ae69d99c0c86806fc2fac5c50 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 11 Apr 2018 09:57:17 +0200 Subject: [PATCH 3/3] address feedback --- xhr.bs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/xhr.bs b/xhr.bs index d5a7f97..b0c48ad 100644 --- a/xhr.bs +++ b/xhr.bs @@ -1301,13 +1301,13 @@ transfer-encoding: chunked

    The override MIME type is initially null and can get a value -when {{overrideMimeType()}} is invoked. Final MIME type is the +when {{overrideMimeType()}} is invoked. The final MIME type is the override MIME type unless that is null in which case it is the response MIME type. -

    Final charset is the return value of these steps: +

    The final charset is the return value of these steps:

      -
    1. Let label be null. +

    2. Let label be null.

    3. If response MIME type's parameters["charset"] exists, then set label to it. @@ -1324,8 +1324,8 @@ when {{overrideMimeType()}} is invoked. Final MIME type<

    4. Return encoding.

    -

    The above steps intentionally do not use final MIME type as it would yield the -wrong result. +

    The above steps intentionally do not use the final MIME type as it would yield +the wrong result.


    @@ -1350,7 +1350,7 @@ or null). Unless stated otherwise it is null.
    1. Set response object to a new {{Blob}} object representing received bytes with - {{Blob/type}} final MIME type. + {{Blob/type}} set to the final MIME type.

    2. Return response object.

    @@ -1362,11 +1362,11 @@ or null). Unless stated otherwise it is null.
  • If response's body is null, then return null. -

  • If final MIME type is not an HTML MIME type or an XML MIME type, then - return null. +

  • If the final MIME type is not an HTML MIME type or an XML MIME type, + then return null.

  • -

    If {{XMLHttpRequest/responseType}} is the empty string and final MIME type is an +

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

    This is restricted to @@ -1375,7 +1375,7 @@ or null). Unless stated otherwise it is null. content.

  • -

    If final MIME type is an HTML MIME type, then run these substeps: +

    If the final MIME type is an HTML MIME type, then:

    1. Let charset be the final charset. @@ -1420,7 +1420,7 @@ or null). Unless stated otherwise it is null. encoding to charset. -

    2. Set document's content type to final MIME type. +

    3. Set document's content type to the final MIME type.

    4. Set document's URL to @@ -1459,7 +1459,7 @@ or null). Unless stated otherwise it is null.

    5. Let charset be the final charset.

    6. -

      If {{XMLHttpRequest/responseType}} is the empty string, charset is null, and +

      If {{XMLHttpRequest/responseType}} is the empty string, charset is null, and the final MIME type is an XML MIME type, then use the rules set forth in the XML specifications to determine the encoding. Let charset be the determined encoding. [[!XML]] [[!XMLNS]] @@ -1505,9 +1505,8 @@ when invoked, must run these steps:

    7. Set override MIME type to the result of parsing mime. -

    8. If override MIME type is failure, then set override MIME type to a new - MIME type whose type is "application" and - subtype is "octet-stream". +

    9. If override MIME type is failure, then set override MIME type to + application/octet-stream.