diff --git a/xhr.bs b/xhr.bs index 4e5f430..b96846a 100644 --- a/xhr.bs +++ b/xhr.bs @@ -14,15 +14,6 @@ urlPrefix: https://w3c.github.io/DOM-Parsing/; spec: dom-parsing type: dfn; text: fragment serializing algorithm; url: dfn-fragment-serializing-algorithm -
-{
-  "HTTP": {
-    "aliasOf": "HTTP11"
-  },
-  "XMLNS": {
-    "aliasOf": "XML-NAMES"
-  }
-}

Introduction

@@ -88,7 +79,7 @@ function fetchStatus(address) {

The {{XMLHttpRequest}} object was initially defined as part of the WHATWG's HTML effort. (Based on Microsoft's implementation many years prior.) -It moved to the W3C in 2006. Extensions (e.g. progress events and +It moved to the W3C in 2006. Extensions (e.g., progress events and cross-origin requests) to {{XMLHttpRequest}} were developed in a separate draft (XMLHttpRequest Level 2) until end of 2011, at which point the two drafts were merged and {{XMLHttpRequest}} became a single @@ -106,32 +97,13 @@ archives: -

Conformance

- -

All diagrams, examples, and notes in this specification are -non-normative, as are all sections explicitly marked non-normative. -Everything else in this specification is normative. - -

The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and -"OPTIONAL" in the normative parts of this specification are to be -interpreted as described in RFC2119. For readability, these words do -not appear in all uppercase letters in this specification. -[[!RFC2119]] - - -

Extensibility

- -

User agents, Working Groups, and other interested parties are -strongly encouraged to discuss new features with the WHATWG -community. -

Terminology

-

This specification uses terminology, cross-linked throughout, from DOM, -DOM Parsing and Serialization, Encoding, Feature Policy, Fetch, File API, HTML, -HTTP, URL, Web IDL, and XML. +

This specification depends on the Infra Standard. [[!INFRA]] + +

This specification uses terminology from DOM, DOM Parsing and Serialization, Encoding, +Feature Policy, Fetch, File API, HTML, URL, Web IDL, and XML. [[!DOM]] [[!DOM-PARSING]] @@ -140,12 +112,11 @@ HTTP, URL, Web IDL, and XML. [[!FETCH]] [[!FILEAPI]] [[!HTML]] -[[!HTTP]] [[!URL]] [[!WEBIDL]] -[[!XML]] [[!XMLNS]] +[[!XML]] [[!XML-NAMES]] + -

It uses the typographic conventions from HTML. [[!HTML]]

Interface {{XMLHttpRequest}}

@@ -214,19 +185,66 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget { }; -

An {{XMLHttpRequest}} object has an associated -{{XMLHttpRequestUpload}} object. +

An {{XMLHttpRequest}} object has an associated: + +

+
upload object +
An {{XMLHttpRequestUpload}} object. + +
state +
One of unsent, opened, headers received, loading, and done; + initially unsent. + +
send() flag +
A flag, initially unset. + +
timeout +
An unsigned integer, initially 0. + +
cross-origin credentials +
A boolean, initially false. + +
request method +
A method. + +
request URL +
A URL. + +
author request headers +
A header list, initially empty. + +
request body +
Initially null. -

An {{XMLHttpRequest}} object has an associated -state, which is one of -unsent, -opened, -headers received, -loading, and -done. Unless stated otherwise it is unsent. +

synchronous flag +
A flag, initially unset. -

An {{XMLHttpRequest}} object has an associated -send() flag. Unless stated otherwise it is unset. +

upload complete flag +
A flag, initially unset. + +
upload listener flag +
A flag, initially unset. + +
timed out flag +
A flag, initially unset. + +
response +
A response, initially a network error. + +
received bytes +
A byte sequence, initially the empty byte sequence. + +
response type +
One of the empty string, "arraybuffer", "blob", + "document", "json", and "text"; initially the empty string. + +
response object +
An object, failure, or null, initially null. + +
override MIME type +
A MIME type or null, initially null. Can get a value when + {{overrideMimeType()}} is invoked. +

Constructors

@@ -236,8 +254,14 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget {
Returns a new {{XMLHttpRequest}} object. -

The XMLHttpRequest() -constructor, when invoked, must return a new {{XMLHttpRequest}} object. +

The +new XMLHttpRequest() +constructor steps are: + +

    +
  1. Set this's upload object to a new + XMLHttpRequestUpload object. +

Garbage collection

@@ -327,10 +351,9 @@ supported as attribute solely by the state. -

The -readyState -attribute's getter must return the value from the table below in the cell of the second column, from -the row where the value in the cell in the first column is context object's state: +

The readyState getter steps are to return +the value from the table below in the cell of the second column, from the row where the value in the +cell in the first column is this's state: @@ -341,48 +364,27 @@ the row where the value in the cell in the first column is context object
opened OPENED (numeric value 1) The open() method has - been successfully invoked. During this state request headers can be set using - setRequestHeader() and the fetch can be initiated using the - send() method. + been successfully invoked. During this state request headers can be set using + setRequestHeader() and the fetch can be initiated using the + send() method.
headers received - HEADERS_RECEIVED - (numeric value 2) - All redirects (if any) have been followed and all HTTP headers of the - response have been received. + HEADERS_RECEIVED (numeric value 2) + All redirects (if any) have been followed and all headers of a response have been received.
loading LOADING (numeric value 3) - The response's - body is being received. + The response body is being received.
done DONE (numeric value 4) - The data transfer has been completed or something went wrong during the transfer - (e.g. infinite redirects). + The data transfer has been completed or something went wrong during the transfer (e.g., + infinite redirects).

Request

-

Each {{XMLHttpRequest}} object has the following request-associated concepts: -request method, -request URL, -author request headers, -request body, -synchronous flag, -upload complete flag, -upload listener flag, and -timed out flag. - -

The author request headers is an initially empty -header list. - -

The request body is initially null. - -

The synchronous flag, upload complete flag, upload listener flag and -timed out flag are initially unset. -

Registering one or more event listeners on an {{XMLHttpRequestUpload}} object will result in a CORS-preflight request. (That is because registering an event listener causes the upload listener flag to be set, which in @@ -399,7 +401,7 @@ turn causes the use-CORS-preflight flag to be set.) synchronous flag.

Throws a "{{SyntaxError!!exception}}" {{DOMException}} if either method is not a - valid HTTP method or url cannot be parsed. + valid method or url cannot be parsed.

Throws a "{{SecurityError!!exception}}" {{DOMException}} if method is a case-insensitive match for `CONNECT`, `TRACE`, or `TRACK`. @@ -420,10 +422,10 @@ agents are strongly encouraged to warn about such usage in developer tools and m open(method, url) and open(method, url, async, username, password) -methods, when invoked, must run these steps: +method steps are:

    -
  1. Let settingsObject be context object's relevant settings object. +

  2. Let settingsObject be this's relevant settings object.

  3. If settingsObject has a responsible document and it is not fully active, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. @@ -463,10 +465,9 @@ methods, when invoked, must run these steps: password.

-
  • If async is false, current global object is a {{Window}} object, and the - {{XMLHttpRequest/timeout!!attribute}} attribute value is not zero or the - {{XMLHttpRequest/responseType}} attribute value is not the empty string, then throw an - "{{InvalidAccessError!!exception}}" {{DOMException}}. +

  • If async is false, the current global object is a {{Window}} object, and + either this's timeout is not 0 or this's response type is not + the empty string, then throw an "{{InvalidAccessError!!exception}}" {{DOMException}}.

  • Terminate the ongoing fetch operated by the @@ -479,29 +480,28 @@ methods, when invoked, must run these steps:

    Set variables associated with the object as follows:

    Override MIME type is not overridden here as the overrideMimeType() method can be invoked before the open() method.

  • -

    If the state is not opened, then: +

    If this's state is not opened, then:

      -
    1. Set state to - opened. +

    2. Set this's state to opened. -

    3. Fire an event named readystatechange at this. +

    4. Fire an event named readystatechange at this.

    @@ -530,10 +530,10 @@ the editing software used to write the XMLHttpRequest Standard. method must run these steps:
      -
    1. If state is not opened, then throw an +

    2. If this's state is not opened, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

    3. If the send() flag is set, then throw an +

    4. If this's send() flag is set, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}.

    5. Normalize value. @@ -545,10 +545,9 @@ method must run these steps:

      An empty byte sequence represents an empty header value. -

    6. Terminate these steps if name is a - forbidden header name. +

    7. If name is a forbidden header name, then return. -

    8. Combine name/value in +

    9. Combine name/value in this's author request headers.

    @@ -569,14 +568,14 @@ client.send(); -

    The timeout attribute

    +

    The timeout getter and setter

    client . timeout

    Can be set to a time in milliseconds. When set to a non-zero value will cause fetching to terminate after the given time has passed. When the time has passed, the - request has not yet completed, and the synchronous flag is unset, a + request has not yet completed, and this's synchronous flag is unset, a timeout event will then be dispatched, or a "{{TimeoutError!!exception}}" {{DOMException}} will be thrown otherwise (for the send() method). @@ -585,17 +584,17 @@ client.send(); synchronous flag is set and current global object is a {{Window}} object.

    -

    The timeout -attribute must return its value. Initially its value must be zero. +

    The timeout getter steps are to return +this's timeout. -

    Setting the {{XMLHttpRequest/timeout!!attribute}} -attribute must run these steps: +

    The {{XMLHttpRequest/timeout!!attribute}} setter steps are:

      -
    1. If current global object is a {{Window}} object and the synchronous flag is - set, then throw an "{{InvalidAccessError!!exception}}" {{DOMException}}. +

    2. If the current global object is a {{Window}} object and this's + synchronous flag is set, then throw an "{{InvalidAccessError!!exception}}" + {{DOMException}}. -

    3. Set its value to the new value. +

    4. Set this's timeout to the given value.

    This implies that the @@ -605,7 +604,7 @@ progress. If that occurs it will still be measured relative to the start of fetching. -

    The withCredentials attribute

    +

    The withCredentials getter and setter

    client . withCredentials @@ -618,32 +617,23 @@ of fetching. unsent or opened, or if the send() flag is set.
    -

    The -withCredentials -attribute must return its value. Initially its value must be false. +

    The withCredentials getter steps are to +return this's cross-origin credentials. -

    Setting the -{{XMLHttpRequest/withCredentials}} -attribute must run these steps: +

    The {{XMLHttpRequest/withCredentials}} setter steps are:

      -
    1. If state is not unsent or opened, then throw an +

    2. If this's state is not unsent or opened, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

    3. If the send() flag is set, then throw an +

    4. If this's send() flag is set, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

    5. Set the {{XMLHttpRequest/withCredentials}} - attribute's value to the given value. +

    6. Set this's cross-origin credentials to the given value.

    -

    The {{XMLHttpRequest/withCredentials}} -attribute has no effect when -fetching -same-origin resources. - -

    The upload attribute

    +

    The upload getter

    client . upload @@ -652,13 +642,8 @@ attribute has no effect when transferred to a server.
    -

    The -upload -attribute must return the associated -{{XMLHttpRequestUpload}} object. - -

    As indicated earlier, each {{XMLHttpRequest}} -object has an associated {{XMLHttpRequestUpload}} object. +

    The upload getter steps are to return +this's upload object.

    The send() method

    @@ -673,18 +658,17 @@ object has an associated {{XMLHttpRequestUpload}} object. opened or the send() flag is set. -

    The send(body) -method must run these steps: +

    The send(body) method steps are:

      -
    1. If state is not opened, then throw an +

    2. If this's state is not opened, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

    3. If the send() flag is set, then throw an +

    4. If this's send() flag is set, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

    5. If the request method is GET or - HEAD, set body to null. +

    6. If this's request method is `GET` or `HEAD`, then + set body to null.

    7. If body is not null, then: @@ -692,27 +676,24 @@ method must run these steps:

      1. Let extractedContentType be null. -

      2. If body is a {{Document}}, then set request body to +

      3. If body is a {{Document}}, then set this's request body to body, serialized, converted, and UTF-8 encoded. -

      4. Otherwise, set request body and extractedContentType to the result of - extracting body. +

      5. Otherwise, set this's request body and extractedContentType to + the result of safely extracting body. + +

      6. Let originalAuthorContentType be the result of getting + `Content-Type` from this's author request headers.

      7. -

        If author request headers contains - `Content-Type`, then: +

        If originalAuthorContentType is non-null, then:

        1. If body is a {{Document}} or a {{USVString}}, then:

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

          2. Let contentTypeRecord be the result of parsing originalAuthorContentType. @@ -730,30 +711,32 @@ method must run these steps: serializing contentTypeRecord.

          3. Set - `Content-Type`/newContentTypeSerialized in + `Content-Type`/newContentTypeSerialized in this's author request headers.

      +
    8. - Otherwise: +

      Otherwise:

      1. If body is an HTML document, set - `Content-Type`/`text/html;charset=UTF-8` in + `Content-Type`/`text/html;charset=UTF-8` in this's author request headers.

      2. Otherwise, if body is an XML document, set - `Content-Type`/`application/xml;charset=UTF-8` in + `Content-Type`/`application/xml;charset=UTF-8` in this's author request headers.

      3. Otherwise, if extractedContentType is not null, set - `Content-Type`/extractedContentType in author request headers. + `Content-Type`/extractedContentType in this's + author request headers.

    -
  • If one or more event listeners are registered on the associated - {{XMLHttpRequestUpload}} object, then set upload listener flag. +

  • If one or more event listeners are registered on this's upload object, then + set this's upload listener flag.

  • Let req be a new @@ -762,60 +745,53 @@ method must run these steps:

    method -
    request method -
    url -
    request URL +
    This's request method. +
    URL +
    This's request URL.
    header list -
    author request headers +
    This's author request headers.
    unsafe-request flag
    Set.
    body -
    request body +
    This's request body.
    client -
    context object's - relevant settings object +
    This's relevant settings object.
    synchronous flag -
    Set if the synchronous flag is set. +
    Set if this's synchronous flag is set.
    mode -
    "cors" +
    "cors".
    use-CORS-preflight flag -
    Set if upload listener flag is set. +
    Set if this's upload listener flag is set.
    credentials mode -
    If the {{XMLHttpRequest/withCredentials}} - attribute value is true, "include", and "same-origin" - otherwise. +
    If this's cross-origin credentials is true, then "include"; + otherwise "same-origin".
    use-URL-credentials flag -
    Set if either request URL's - username - is not the empty string or request URL's - password is non-null. +
    Set if this's request URL includes credentials.
    -
  • Unset the upload complete flag. +

  • Unset this's upload complete flag. -

  • Unset the timed out flag. +

  • Unset this's timed out flag. -

  • If req's - body is null, - set the upload complete flag. +

  • If req's body is null, then set this's + upload complete flag. -

  • Set the send() flag. +

  • Set this's send() flag.

  • -

    If the synchronous flag is unset, then: +

    If this's synchronous flag is unset, then:

      -
    1. Fire a progress event named loadstart at this with 0 and 0. +

    2. Fire a progress event named loadstart at this + with 0 and 0. -

    3. If the upload complete flag is unset and upload listener flag is - set, then fire a progress event named - loadstart at this's - {{XMLHttpRequestUpload}} object with 0 and req's - body's - total bytes. +

    4. If this's upload complete flag is unset and this's + upload listener flag is set, then fire a progress event named + loadstart at this's upload object with 0 and + req's body's total bytes. -

    5. If state is not opened or the send() flag is unset, then - return. +

    6. If this's state is not opened or this's + send() flag is unset, then return.

    7. Fetch req. @@ -826,16 +802,11 @@ method must run these steps:

      Run these steps in parallel:

        -
      1. -

        Wait until either req's done flag is set or - -

          -
        1. the {{XMLHttpRequest/timeout!!attribute}} attribute value number of milliseconds has - passed since these steps started -

        2. while {{XMLHttpRequest/timeout!!attribute}} attribute value is not zero. -

        +
      2. Wait until either req's done flag is set or this's + timeout is not 0 and this's timeout milliseconds have passed since these + steps started. -

      3. If req's done flag is unset, then set the +

      4. If req's done flag is unset, then set this's timed out flag and terminate fetching.

      @@ -845,15 +816,10 @@ method must run these steps:
    8. If not roughly 50ms have passed since these steps were last invoked, terminate these steps. -

    9. If upload listener flag is set, then - fire a progress event named - progress at this's - {{XMLHttpRequestUpload}} object with request's - body's - transmitted bytes and - request's - body's - total bytes. +

    10. If this's upload listener flag is set, then fire a progress event + named progress at this's upload object with + request's body's transmitted bytes and + request's body's total bytes.

    @@ -862,9 +828,9 @@ method must run these steps:

    To process request end-of-body for request, run these steps:

      -
    1. Set the upload complete flag. +

    2. Set this's upload complete flag. -

    3. If upload listener flag is unset, then terminate these steps. +

    4. If this's upload listener flag is unset, then terminate these steps.

    5. Let transmitted be request's body's @@ -874,50 +840,41 @@ method must run these steps: body's total bytes. -

    6. Fire a progress event named - progress at this's - {{XMLHttpRequestUpload}} object with transmitted and - length. +

    7. Fire a progress event named progress at this's + upload object with transmitted and length. -

    8. Fire a progress event named - load at this's - {{XMLHttpRequestUpload}} object with transmitted and - length. +

    9. Fire a progress event named load at this's + upload object with transmitted and length. -

    10. Fire a progress event named - loadend at this's - {{XMLHttpRequestUpload}} object with transmitted and - length. +

    11. Fire a progress event named loadend at this's + upload object with transmitted and length.

    To process response for response, run these steps:

      -
    1. Set response to response. +

    2. Set this's response to response. -

    3. Handle errors for response. +

    4. Handle errors fo this and response. -

    5. If response is a - network error, +

    6. If this's response is a network error, then return. -

    7. Set state to - headers received. +

    8. Set this's state to headers received. -

    9. Fire an event named - readystatechange at this. +

    10. Fire an event named readystatechange at this. -

    11. If state is not - headers received, then return. +

    12. If this's state is not headers received, then return. -

    13. If response's - body is null, - then run handle response end-of-body and return. +

    14. If this's response's body is null, + then run handle response end-of-body for this and this's + response, and then return.

    15. Let reader be the result of getting a reader for - response's body's stream. + this's response's body's + stream.

      This operation will not throw an exception. @@ -928,35 +885,36 @@ method must run these steps:

      chunk steps, given chunk
        -
      1. Append chunk to received bytes. +

      2. Append chunk to this's received bytes.

      3. If not roughly 50ms have passed since these steps were last invoked, then abort these steps. -

      4. If state is headers received, then set state to loading. +

      5. If this's state is headers received, then set this's + state to loading.

      6. -

        Fire an event named readystatechange at this. +

        Fire an event named readystatechange at this.

        Web compatibility is the reason - readystatechange fires more often than state changes. + readystatechange fires more often than this's + state changes. -

      7. Fire a progress event named progress at this - with response's body's transmitted bytes and - response's body's total bytes. +

      8. Fire a progress event named progress at this + with this's response's body's + transmitted bytes and this's response's + body's total bytes.

      close steps
      -
        -
      1. Run handle response end-of-body for response. -

      +
      1. Run handle response end-of-body for this and this's + response.

      error steps
      -
        -
      1. Run handle errors for response. -

      +
      1. Run handle errors for this and this's + response.

    16. Read a chunk from reader given @@ -965,25 +923,23 @@ method must run these steps:

  • -

    Otherwise, if the synchronous flag is set, run these steps: +

    Otherwise, if this's synchronous flag is set:

      -
    1. If context object's relevant settings object has a - responsible document which is not allowed to use the - "sync-xhr" feature, then run handle response end-of-body for a - network error and return. +

    2. If this's relevant settings object has a responsible document which + is not allowed to use the "sync-xhr" feature, then run + handle response end-of-body for this and a network error, and then return.

    3. Let response be the result of fetching req. -

      If the {{XMLHttpRequest/timeout!!attribute}} attribute value is not zero, then set the - timed out flag and terminate fetching if it has not - returned within the amount of milliseconds from the {{XMLHttpRequest/timeout!!attribute}}. +

      If this's timeout is not 0, then set this's timed out flag and + terminate fetching if it has not returned within this's + timeout milliseconds. -

    4. If response's - body is null, - then run handle response end-of-body and return. +

    5. If response's body is null, then run + handle response end-of-body for this and response, and then return.

    6. Let reader be the result of getting a reader for @@ -997,27 +953,27 @@ method must run these steps:

    7. Wait for promise to be fulfilled or rejected.

    8. If promise is fulfilled with bytes, then append bytes - to received bytes. + to this's received bytes. -

    9. Run handle response end-of-body for response. +

    10. Run handle response end-of-body for this and response.

    -

    To handle response end-of-body for -response, run these steps: +

    To handle response end-of-body for an +{{XMLHttpRequest}} object xhr and a response response, run these +steps:

      -
    1. If the synchronous flag is set, set response to - response. +

    2. If xhr's synchronous flag is set, then set xhr's + response to response. -

    3. Handle errors for response. +

    4. Handle errors for xhr and response. -

    5. If response is a - network error, return. +

    6. If xhr's response is a network error, then + return. -

    7. If the synchronous flag is unset, update response's - body using - response. +

    8. If xhr's synchronous flag is unset, then update xhr's + response's body using response.

    9. Let transmitted be response's body's transmitted bytes. @@ -1025,34 +981,35 @@ method must run these steps:

    10. Let length be response's body's total bytes. -

    11. If the synchronous flag is unset, fire a progress event named - progress at this with transmitted and length. +

    12. If xhr's synchronous flag is unset, then fire a progress event + named progress at xhr with transmitted and + length. -

    13. Set state to done. +

    14. Set xhr's state to done. -

    15. Unset the send() flag. +

    16. Unset xhr's send() flag. -

    17. Fire an event named readystatechange at this. +

    18. Fire an event named readystatechange at xhr. -

    19. Fire a progress event named load - at this - with transmitted and length. +

    20. Fire a progress event named load at xhr with + transmitted and length. -

    21. Fire a progress event named loadend - at this - with transmitted and length. +

    22. Fire a progress event named loadend at xhr with + transmitted and length.

    -

    To handle errors for response run these steps: +

    To handle errors for an {{XMLHttpRequest}} object xhr and a +response response, run these steps:

      -
    1. If the send() flag is unset, return. +

    2. If xhr's send() flag is unset, then return. -

    3. If the timed out flag is set, then run the request error steps for event - timeout and exception "{{TimeoutError!!exception}}" {{DOMException}}. +

    4. If xhr's timed out flag is set, then run the request error steps + for xhr, timeout, and "{{TimeoutError!!exception}}" + {{DOMException}}.

    5. If response is a network error, then run the request error steps - for event error and exception "{{NetworkError!!exception}}" + for xhr, error, and "{{NetworkError!!exception}}" {{DOMException}}.

    6. @@ -1060,61 +1017,57 @@ method must run these steps: errored, then:
        -
      1. Set state to done. +

      2. Set xhr's state to done. -

      3. Unset the send() flag. +

      4. Unset xhr's send() flag. -

      5. Set response to a network error. +

      6. Set xhr's response to a network error.

      -
    7. Otherwise, if response's aborted flag is set, then run the - request error steps for event abort and exception - "{{AbortError!!exception}}" {{DOMException}}. +

    8. Otherwise, if xhr's response's aborted flag is + set, then run the request error steps for xhr, abort, + and "{{AbortError!!exception}}" {{DOMException}}.

    -

    The request error steps for event event and optionally an -exception exception are: +

    The request error steps for an {{XMLHttpRequest}} object xhr, +event, and optionally exception are:

      -
    1. Set state to done. +

    2. Set xhr's state to done. -

    3. Unset the send() flag. +

    4. Unset xhr's send() flag. -

    5. Set response to a - network error. +

    6. Set xhr's response to a network error. -

    7. If the synchronous flag is set, - throw an exception - exception. +

    8. If xhr's synchronous flag is set, then throw exception.

    9. -

      Fire an event named readystatechange at this. +

      Fire an event named readystatechange at xhr. -

      At this point it is clear that the synchronous flag is unset. +

      At this point it is clear that xhr's synchronous flag is unset.

    10. -

      If the upload complete flag is unset, then: +

      If xhr's upload complete flag is unset, then:

        -
      1. Set the upload complete flag. +

      2. Set xhr's upload complete flag.

      3. -

        If the upload listener flag is set, then: +

        If xhr's upload listener flag is set, then:

          -
        1. Fire a progress event named event at this's {{XMLHttpRequestUpload}} - object with 0 and 0. +

        2. Fire a progress event named event at xhr's + upload object with 0 and 0. -

        3. Fire a progress event named loadend at this's - {{XMLHttpRequestUpload}} object with 0 and 0. +

        4. Fire a progress event named loadend at xhr's + upload object with 0 and 0.

      -
    11. Fire a progress event named - event at this with 0 and 0. +

    12. Fire a progress event named event at xhr with 0 and 0. -

    13. Fire a progress event named - loadend at this with 0 and 0. +

    14. Fire a progress event named loadend at xhr + with 0 and 0.

    @@ -1125,69 +1078,53 @@ exception exception are:
    Cancels any network activity. -

    The abort() method, -when invoked, must run these steps: +

    The abort() method steps are:

    1. Terminate the ongoing fetch with the aborted flag set. -

    2. If state is either - opened with the send() flag set, - headers received, or loading, run the - request error steps for event abort. +

    3. If this's state is opened with this's + send() flag set, headers received, or loading, then run the + request error steps for this and abort.

    4. -

      If state is done, then set state to unsent and response to a - network error. +

      If this's state is done, then set this's state to + unsent and this's response to a network error. -

      No readystatechange event - is dispatched. +

      No readystatechange event is dispatched.

    Response

    -

    An {{XMLHttpRequest}} has an associated response. Unless stated -otherwise it is a -network error. - -

    An {{XMLHttpRequest}} also has an associated received bytes (a byte -sequence). Unless stated otherwise it is the empty byte sequence. +

    The responseURL getter

    +

    The responseURL getter steps are to return +the empty string if this's response's URL is +null; otherwise its serialization with the exclude fragment flag +set. -

    The responseURL attribute

    -

    The responseURL attribute -must return the empty string if response's -url is null and its -serialization with the -exclude fragment flag set otherwise. +

    The status getter

    +

    The status getter steps are to return +this's response's status. -

    The status attribute

    -

    The -status -attribute must return the response's -status. +

    The statusText getter

    - -

    The statusText attribute

    - -

    The -statusText -attribute must return the response's -status message. +

    The statusText getter steps are to return +this's response's status message.

    The getResponseHeader() method

    -

    The getResponseHeader(name) method, -when invoked, must return the result of getting name from -response's header list +

    The getResponseHeader(name) method +steps are to return the result of getting name from +this's response's header list. -

    The Fetch Standard filters response's -header list. [[!FETCH]] +

    The Fetch Standard filters this's +response's header list. [[!FETCH]]

    For the following script: @@ -1222,15 +1159,13 @@ text/plain; charset=UTF-8

  • Return A is byte less than B. -

    The -getAllResponseHeaders() -method, when invoked, must run these steps: +

    The getAllResponseHeaders() method steps are:

    1. Let output be an empty byte sequence.

    2. Let initialHeaders be the result of running sort and combine with - response's header list. + this's response's header list.

    3. Let headers be the result of sorting initialHeaders in @@ -1247,9 +1182,8 @@ method, when invoked, must run these steps:

    4. Return output.

    -

    The Fetch Standard filters response's -header list. -[[!FETCH]] +

    The Fetch Standard filters this's +response's header list. [[!FETCH]]

    For the following script: @@ -1279,32 +1213,44 @@ transfer-encoding: chunked

    Response body

    -

    The response MIME type is the result of running these steps: +

    To get a response MIME type for an {{XMLHttpRequest}} object +xhr, run these steps:

    1. Let mimeType be the result of extracting a MIME type - from response's header list. + from xhr's response's header list.

    2. If mimeType is failure, then set mimeType to text/xml.

    3. Return mimeType.

    -

    The override MIME type is initially null and can get a value -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. +

    To get a final MIME type for an {{XMLHttpRequest}} object +xhr, run these steps: + +

      +
    1. If xhr's override MIME type is null, return the result of + get a response MIME type for xhr. + +

    2. Return xhr's override MIME type. +

    -

    The final charset is the return value of these steps: +

    To get a final encoding for an {{XMLHttpRequest}} object +xhr, run these steps:

    1. Let label be null. -

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

    3. Let responseMIME be the result of get a response MIME type for + xhr. -

    4. If override MIME type's parameters["charset"] +

    5. If responseMIME's parameters["charset"] exists, then set label to it. +

    6. If xhr's 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. @@ -1314,65 +1260,39 @@ when {{overrideMimeType()}} is invoked. The final MIME t

    9. Return encoding.

    -

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

    The above steps intentionally do not use the get a final MIME type as it would +not be web compatible.


    -

    An {{XMLHttpRequest}} object has an associated response object (an object, failure, -or null). Unless stated otherwise it is null. - - -

    An arraybuffer response is the return value of these steps: - -

      -
    1. -

      Set response object to a new {{ArrayBuffer}} object representing received bytes. - If this throws an exception, then set response object to failure and return null. - -

      Allocating an {{ArrayBuffer}} object is not guaranteed to succeed. [[!ECMASCRIPT]] - -

    2. Return response object. -

    - - -

    A blob response is the return value of these steps: +

    To set a document response for an {{XMLHttpRequest}} object +xhr, run these steps:

      -
    1. Set response object to a new {{Blob}} object representing received bytes with - {{Blob/type}} set to the final MIME type. +

    2. If xhr's response's body is null, + then return. -

    3. Return response object. -

    - - -

    A document response is the return value of these steps: - -

      -
    1. If response's - body is null, then return null. +

    2. Let finalMIME be the result of get a final MIME type for xhr. -

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

    4. If finalMIME is not an HTML MIME type or an XML MIME type, then + return.

    5. -

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

      If xhr's response type is the empty string and finalMIME is an + HTML MIME type, then return. -

      This is restricted to - {{XMLHttpRequest/responseType}} being - "document" in order to prevent breaking legacy - content. +

      This is restricted to xhr's response type being + "document" in order to prevent breaking legacy content.

    6. -

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

      If finalMIME is an HTML MIME type, then:

        -
      1. Let charset be the final charset. +

      2. Let charset be the result of get a final encoding for xhr.

      3. If charset is null, prescan - the first 1024 bytes of received bytes and if + the first 1024 bytes of xhr's received bytes and if that does not terminate unsuccessfully then let charset be the return value. @@ -1380,7 +1300,7 @@ or null). Unless stated otherwise it is null.

      4. Let document be a document that - represents the result parsing received bytes following the rules set + represents the result parsing xhr's received bytes following the rules set forth in the HTML Standard for an HTML parser with scripting disabled and a known definite encoding charset. [[!HTML]] @@ -1390,13 +1310,10 @@ or null). Unless stated otherwise it is null.

    7. -

      Otherwise, let document be a - document - that represents the result of running the XML parser - with XML scripting support disabled on +

      Otherwise, let document be a document that represents the result of running + the XML parser with XML scripting support disabled on xhr's received bytes. If that fails (unsupported character encoding, - namespace well-formedness error, etc.), then return null. - [[!HTML]] + namespace well-formedness error, etc.), then return null. [[!HTML]]

      Resources referenced will not be loaded and no associated XSLT will be applied. @@ -1404,65 +1321,41 @@ or null). Unless stated otherwise it is null.

    8. If charset is null, then set charset to UTF-8. -

    9. Set document's - encoding to - charset. +

    10. Set document's encoding to charset. -

    11. Set document's content type to the final MIME type. +

    12. Set document's content type to finalMIME. -

    13. Set document's - URL to - response's - url. +

    14. Set document's URL to xhr's + response's URL. -

    15. Set document's origin to - context object's - relevant settings object's - origin. +

    16. Set document's origin to xhr's + relevant settings object's origin. -

    17. Set response object to - document and return it. +

    18. Set xhr's response object to document.

    - -

    A JSON response is the return value of these steps: +

    To get a text response for an +{{XMLHttpRequest}} object xhr, run these steps:

      -
    1. If response's body is null, then return null. - -

    2. Let jsonObject be the result of running parse JSON from bytes on - received bytes. If that threw an exception, then return null. - -

    3. Set response object to jsonObject and return it. -

    - +
  • If xhr's response's body is null, + then return the empty string. -

    A text response is the return value of these steps: - -

      -
    1. If response's - body is null, then return the - empty string. - -

    2. Let charset be the final charset. +

    3. Let charset be the result of get a final encoding for xhr.

    4. -

      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]] +

      If xhr's response type is the empty string, charset is null, and + the result of get a final MIME type for xhr 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]] [[!XML-NAMES]] -

      This is restricted to - {{XMLHttpRequest/responseType}} being - the empty string to keep the non-legacy - {{XMLHttpRequest/responseType}} value - "text" simple. +

      This is restricted to xhr's response type being the empty string + to keep the non-legacy response type value "text" simple.

    5. If charset is null, then set charset to UTF-8. -

    6. Return the result of running - decode on received bytes using fallback - encoding charset. +

    7. Return the result of running decode on xhr's received bytes using + fallback encoding charset.

    Authors are strongly encouraged to always encode their resources using UTF-8. @@ -1473,29 +1366,29 @@ or null). Unless stated otherwise it is null.

    client . overrideMimeType(mime)
    -

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

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

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

    -

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

    The overrideMimeType(mime) method +steps are:

      -
    1. If state is loading or done, then throw an +

    2. If this's state is loading or done, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

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

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

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

    6. If this's override MIME type is failure, then set this's + override MIME type to application/octet-stream.

    -

    The responseType attribute

    +

    The responseType getter and setter

    client . responseType [ = value ] @@ -1519,145 +1412,137 @@ when invoked, must run these steps: synchronous flag is set and current global object is a {{Window}} object.
    +

    The responseType getter steps are to return +this's response type. -

    The -responseType -attribute must return its value. Initially its value must be the empty -string. - -

    Setting the -{{XMLHttpRequest/responseType}} -attribute must run these steps: +

    The {{XMLHttpRequest/responseType}} setter steps are:

      -
    1. If current global object is not a - {{Window}} object and the given value is - "document", terminate these steps. +

    2. If the current global object is not a {{Window}} object and the given value is + "document", then return. -

    3. If state is loading or done, then throw an +

    4. If this's state is loading or done, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

    5. If current global object is a {{Window}} object and the synchronous flag is - set, then throw an "{{InvalidAccessError!!exception}}" {{DOMException}}. +

    6. If the current global object is a {{Window}} object and this's + synchronous flag is set, then throw an "{{InvalidAccessError!!exception}}" + {{DOMException}}. -

    7. Set the - {{XMLHttpRequest/responseType}} - attribute's value to the given value. +

    8. Set this's response type to the given value.

    -

    The response attribute

    +

    The response getter

    client . response -

    Returns the response's - body. +

    Returns the response body.

    -

    The -response -attribute must return the result of running these -steps: +

    The response getter steps are: + +

      +
    1. +

      If this's response type is the empty string or "text", then: -

      -
      If {{XMLHttpRequest/responseType}} - is the empty string or "text" -
        -
      1. If state is not - loading or done, return the empty string. +

      2. If this's state is not loading or done, then return + the empty string. -

      3. Return the text response. +

      4. Return the result of getting a text response for this.

      -
      Otherwise -
      +
    2. If this's state is not done, then return null. + +

    3. If this's response object is failure, then return null. + +

    4. If this's response object is non-null, then return it. + +

    5. +

      If this's response type is "arraybuffer", then set this's + response object to a new {{ArrayBuffer}} object representing this's + received bytes. If this throws an exception, then set this's response object + to failure and return null. + +

      Allocating an {{ArrayBuffer}} object is not guaranteed to succeed. [[!ECMASCRIPT]] + +

    6. Otherwise, if this's response type is "blob", + set this's response object to a new {{Blob}} object representing + this's received bytes with {{Blob/type}} set to the result of + get a final MIME type for this. + +

    7. Otherwise, if this's response type is "document", + set a document response for this. + +

    8. +

      Otherwise: +

        -
      1. If state is not - done, return null. +

      2. Assert: this's response type is "json". -

      3. If response object is failure, then return null. +

      4. If this's response's body is null, + then return null. -

      5. If response object is non-null, then return it. +

      6. Let jsonObject be the result of running parse JSON from bytes on + this's received bytes. If that threw an exception, then return null. -

      7. -
        -
        If - {{XMLHttpRequest/responseType}} is - "arraybuffer" -

        Return the arraybuffer response. - -

        If - {{XMLHttpRequest/responseType}} is - "blob" -

        Return the blob response. - -

        If - {{XMLHttpRequest/responseType}} is - "document" -

        Return the document response. - -

        If - {{XMLHttpRequest/responseType}} is - "json" -

        Return the JSON response. -

        +
      8. Set this's response object to jsonObject.

      -
    9. + +
    10. Return this's response object. +

    -

    The responseText attribute

    +

    The responseText getter

    client . responseText
    -

    Returns the text response. +

    Returns response as text.

    Throws an "{{InvalidStateError!!exception}}" {{DOMException}} if {{XMLHttpRequest/responseType}} is not the empty string or "text".

    -

    The -responseText -attribute must return the result of running these -steps: +

    The responseText getter steps are:

      -
    1. If {{XMLHttpRequest/responseType}} is not the empty string or "text", then +

    2. If this's response type is not the empty string or "text", then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

    3. If state is not loading or done, then return the empty string. +

    4. If this's state is not loading or done, then return + the empty string. -

    5. Return the text response. +

    6. Return the result of getting a text response for this.

    -

    The responseXML attribute

    +

    The responseXML getter

    client . responseXML
    -

    Returns the document response. +

    Returns the response as document.

    Throws an "{{InvalidStateError!!exception}}" {{DOMException}} if {{XMLHttpRequest/responseType}} is not the empty string or "document".

    -

    The -responseXML -attribute must return the result of running these steps: +

    The responseXML getter steps are:

      -
    1. If {{XMLHttpRequest/responseType}} is not the empty string or "document", then - throw an "{{InvalidStateError!!exception}}" {{DOMException}}. +

    2. If this's response type is not the empty string or "document", + then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. + +

    3. If this's state is not done, then return null. -

    4. If state is not done, then return null. +

    5. Assert: this's response object is not failure. -

    6. Assert: response object is not failure. +

    7. If this's response object is non-null, then return it. -

    8. If response object is non-null, then return it. +

    9. Set a document response for this. -

    10. Return the document response. +

    11. Return this's response object.

    @@ -1776,12 +1661,10 @@ attribute.

    The -FormData(form) -constructor must run these steps: +new FormData(form) +constructor steps are:

      -
    1. Let fd be a new {{FormData}} object. -

    2. If form is given, then: @@ -1792,78 +1675,87 @@ constructor must run these steps:

    3. If list is null, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -

    4. Set fd's entry list to list. +

    5. Set this's entry list to list.

    - -
  • Return fd.

    The append(name, value) and append(name, blobValue, filename) -methods, when invoked, must run these steps: +method steps are:

      -
    1. Let value be value if given, and blobValue otherwise. +

    2. Let value be value if given; otherwise blobValue.

    3. Let entry be the result of creating an entry with name, value, and filename if given. -

    4. Append entry to the context object's - entry list. +

    5. Append entry to this's entry list.

    The reason there is an argument named value as well as blobValue is due to a limitation of the editing software used to write the XMLHttpRequest Standard.

    The delete(name) -method, when invoked, must remove all entries whose -name is name from the context object's -entry list. +method steps are to remove all entries whose +name is name from this's entry list. + +

    The get(name) method +steps are: -

    The get(name) method, -when invoked, must return the value of the first entry -whose name is name from the context object's -entry list, and null otherwise. +

      +
    1. If there is no entry whose name is + name in this's entry list, then return null. + +

    2. Return the value of the first entry whose + name is name from this's + entry list. +

    The getAll(name) -method, when invoked, must return the values of all -entries whose name is name, in order, from -the context object's entry list, and the empty list otherwise. +method steps are: + +

      +
    1. If there is no entry whose name is + name in this's entry list, then return the empty list. -

      The has(name) method, -when invoked, must return true if there is an entry whose -name is name in the context object's -entry list, and false otherwise. +

    2. Return the values of all entries whose + name is name, in order, from this's + entry list. +

    + +

    The has(name) method +steps are to return true if there is an entry whose +name is name in this's entry list; +otherwise false.

    The set(name, value) and set(name, blobValue, filename) -methods, when invoked, must run these steps: +method steps are:

      -
    1. Let value be value if given, and blobValue otherwise. +

    2. Let value be value if given; otherwise blobValue.

    3. Let entry be the result of creating an entry with name, value, and filename if given. -

    4. If there are any entries in the context object's - entry list whose name is name, then - replace the first such entry with entry and - remove the others. +

    5. If there are entries in this's entry list + whose name is name, then replace the first + such entry with entry and remove the others. -

    6. Otherwise, append entry to the context object's +

    7. Otherwise, append entry to this's entry list.

    The reason there is an argument named value as well as blobValue is due to a limitation of the editing software used to write the XMLHttpRequest Standard. -

    The value pairs to iterate over are the context object's -entry list's entries with the key being the -name and the value being the value. +

    The value pairs to iterate over are this's entry list's +entries with the key being the name and the value +being the value.

    Interface {{ProgressEvent}}

    @@ -1891,7 +1783,7 @@ dictionary ProgressEventInit : EventInit { lengthComputable, loaded, and total -attributes must return the value they were initialized to. +getter steps are to return the value they were initialized to.

    Firing events using the {{ProgressEvent}} interface

    @@ -1972,12 +1864,12 @@ attributes initialized to false, so it is suggested that for consistency all

    Security considerations

    -

    For cross-origin requests some kind of opt-in, e.g. the +

    For cross-origin requests some kind of opt-in, e.g., the CORS protocol defined in the Fetch Standard, has to be used before events using the {{ProgressEvent}} interface are dispatched -as information (e.g. size) would be revealed that cannot be obtained +as information (e.g., size) would be revealed that cannot be obtained otherwise. [[!FETCH]] @@ -2015,6 +1907,7 @@ otherwise. [[!FETCH]]

  • +

    Acknowledgments

    Thanks to @@ -2128,7 +2021,7 @@ Zhenbin Xu for their contributions to this standard.

    Special thanks to the Microsoft employees who first implemented the -XMLHttpRequest interface, which was first widely deployed by the +{{XMLHttpRequest}} interface, which was first widely deployed by the Windows Internet Explorer browser.

    Special thanks to Ian Hickson for drafting an initial version of this specification in