diff --git a/fetch.bs b/fetch.bs index c135722ab..0d19e5c82 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1189,38 +1189,48 @@ or "worker".

In parallel, while true:

    -
  1. Wait for read to be fulfilled or rejected. -

  2. -

    If read is fulfilled with an object whose done property is false - and whose value property is a Uint8Array object, then run these steps: +

    Run these steps, but abort if the ongoing fetch is terminated:

      -
    1. Let bs be the byte sequence represented by the Uint8Array - object. +

    2. Wait for read to be fulfilled or rejected.

    3. -

      Transmit bs. Whenever one or more bytes are transmitted, increase - body's transmitted bytes by the number of transmitted bytes and - queue a fetch task on request to process request body - for request. +

      If read is fulfilled with an object whose done property is false + and whose value property is a Uint8Array object, then run these + steps: -

      This step blocks until bs is fully transmitted. +

        +
      1. Let bs be the byte sequence represented by the + Uint8Array object. -

      2. Set read to the result of reading a - chunk from body's stream with reader. -

      +
    4. +

      Transmit bs. Whenever one or more bytes are transmitted, increase + body's transmitted bytes by the number of transmitted bytes and + queue a fetch task on request to process request body + for request. + +

      This step blocks until bs is fully transmitted. + +

    5. Set read to the result of reading a + chunk from body's stream with reader. +

    + +
  3. Otherwise, if read is fulfilled with an object whose done + property is true, then queue a fetch task on request to + process request end-of-body for request and abort these in-parallel steps. -

  4. Otherwise, if read is fulfilled with an object whose done property - is true, then queue a fetch task on request to - process request end-of-body for request and abort these steps. +

  5. Otherwise, if read is rejected with an + "AbortError" {{DOMException}}, + terminate the ongoing fetch with the aborted flag set. -

  6. Otherwise, terminate the ongoing fetch with reason - fatal and abort these steps. +

  7. Otherwise, terminate the ongoing fetch. +

+ +
  • If the ongoing fetch is terminated, then abort these in-parallel steps. -

    Responses

    The result of fetch is a @@ -1238,8 +1248,10 @@ evolves over time. That is, not all its fields are available straight away. Unless stated otherwise, it is "default".

    A response can have an associated -termination reason -which is end-user abort, fatal, or timeout. +aborted flag, which is initially unset. + +

    This indicates that the request was intentionally aborted by the developer or +end-user.

    A response has an associated url. It is a pointer to the @@ -1277,6 +1289,10 @@ Unless stated otherwise it is `OK`. trailer (a header list). Unless stated otherwise it is empty. +

    A response has an associated +trailer failed flag, which is +initially unset. +

    A response has an associated HTTPS state (an HTTPS state value). Unless stated otherwise, it is @@ -1310,6 +1326,10 @@ navigate algorithm. It ensures `Location` has


    +

    A response whose +type is "error" and aborted flag is set is +known as an aborted network error. +

    A response whose type is "error" is known as a network error. @@ -1472,7 +1492,7 @@ for each associated fetch record whose keepalive flag is unset, terminate the fetch record's -fetch with reason fatal. +fetch.

    Connections

    @@ -1488,21 +1508,38 @@ for each associated fetch record whose origin and credentials, run these steps:
      -
    1. If connection pool contains a - connection whose origin is origin and - credentials is credentials, return that +

    2. If connection pool contains a connection whose origin is + origin and credentials is credentials, then return that connection. +

    3. Let connection be null. +

    4. -

      Let connection be the result of establishing an HTTP connection to - origin. [[!HTTP]] [[!HTTP-SEMANTICS]] [[!HTTP-COND]] [[!HTTP-CACHING]] [[!HTTP-AUTH]] [[!TLS]] +

      Run these steps, but abort if the ongoing fetch is terminated:

      + +
        +
      1. +

        Set connection to the result of establishing an HTTP connection to + origin. [[!HTTP]] [[!HTTP-SEMANTICS]] [[!HTTP-COND]] [[!HTTP-CACHING]] [[!HTTP-AUTH]] + [[!TLS]] -

        If credentials is false, do not send a TLS client certificate. +

        If credentials is false, then do not send a TLS client certificate. -

        If establishing a connection does not succeed (e.g., a DNS, TCP, or TLS error), return failure. +

        If establishing a connection does not succeed (e.g., a DNS, TCP, or TLS error), then return + failure. +

      -
    5. Add connection to the connection pool - with origin being origin and credentials being credentials. +

    6. +

      If the ongoing fetch is terminated, then: + +

        +
      1. If connection is not null, then close connection. + +

      2. Return failure. +

      + +
    7. Add connection to the connection pool with origin + being origin and credentials being credentials.

    8. Return connection.

    @@ -1776,8 +1813,8 @@ from a {{ReadableStream}} object with reader, run these steps:

    To cancel a -{{ReadableStream}} object with reader and reason, return the result of calling -ReadableStreamCancel(reader, reason). +{{ReadableStream}} object stream with reason, return the result of calling +ReadableStreamCancel(stream, reason).

    Because the reader grants exclusive access, the actual mechanism of how to read cannot be observed. Implementations could use more direct mechanism if convenient. @@ -2278,9 +2315,8 @@ pertain to them. Also, considering "image" was not compatible with

    To perform a fetch using request, run the steps below. An ongoing fetch can be -terminated with reason -reason, which must be end-user abort, fatal, -timeout, or garbage collection. +terminated with flag aborted, +which is unset unless otherwise specified.

    The user agent may be asked to suspend the ongoing fetch. @@ -2295,125 +2331,141 @@ the request. [[!HTTP-CACHING]]

      -
    1. If request's window is - "client", set request's - window to request's - client, if request's - client's - global object is a - {{Window}} object, and to "no-window" - otherwise. - -

    2. If request's origin is - "client", set request's - origin to request's - client's origin. -

    3. -

      If request's header list - does not contain `Accept`, then: +

      Run these steps, but abort if the ongoing fetch is terminated:

        -
      1. Let value be `*/*`. +

      2. If request's window is + "client", set request's + window to request's + client, if request's + client's + global object is a + {{Window}} object, and to "no-window" + otherwise. -

      3. If request is a navigation request, a user agent should set - value to - `text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`. +

      4. If request's origin is + "client", set request's + origin to request's + client's origin.

      5. -

        Otherwise, a user agent should set value to the first matching statement, if any, - switching on request's destination: - +

        If request's header list + does not contain `Accept`, then: -

        -
        "image" -
        `image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5` +
          +
        1. Let value be `*/*`. -

          "style" -
          `text/css,*/*;q=0.1` -
        +
      6. If request is a navigation request, a user agent should set + value to + `text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`. -

      7. Append - `Accept`/value to request's - header list. -

      +
    4. +

      Otherwise, a user agent should set value to the first matching statement, if + any, switching on request's destination: + -

    5. If request's header list - does not contain `Accept-Language`, user agents should - append - `Accept-Language`/an appropriate value - to request's header list. +

      +
      "image" +
      `image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5` -
    6. -

      If request's priority is null, then use request's - initiator and destination appropriately in setting - request's priority to a user-agent-defined object. +

      "style" +
      `text/css,*/*;q=0.1` +
    7. -

      The user-agent-defined object could encompass stream weight and dependency - for HTTP/2, and equivalent information used to prioritize dispatch and processing of - HTTP/1 fetches. +

    8. Append + `Accept`/value to request's + header list. +

    -
  • -

    If request is a navigation request, a user agent should, for each - header name (hintName) in the first column of the - following table, if request's header list - does not contain hintName, then - append - hintName/the value given in the same row on the second column, to request's - header list. - - - - - - -
    Name - Value -
    `dpr` - a suitable dpr value -
    `save-data` - a suitable save-data value -
    `viewport-width` - a suitable viewport-width value -
    +

  • If request's header list + does not contain `Accept-Language`, user agents should + append + `Accept-Language`/an appropriate value + to request's header list. -

  • -

    If request is a subresource request, run these substeps: +

  • +

    If request's priority is null, then use request's + initiator and destination appropriately in setting + request's priority to a user-agent-defined object. + +

    The user-agent-defined object could encompass stream weight and dependency + for HTTP/2, and equivalent information used to prioritize dispatch and processing of + HTTP/1 fetches. -

    1. -

      If request's client hints list is not empty, then run these - substeps for each hintName in the list: +

      If request is a navigation request, a user agent should, for each + header name (hintName) in the first column of the + following table, if request's header list + does not contain hintName, then + append + hintName/the value given in the same row on the second column, to + request's header list. + + + + + + +
      Name + Value +
      `dpr` + a suitable dpr value +
      `save-data` + a suitable save-data value +
      `viewport-width` + a suitable viewport-width value +
      + +

    2. +

      If request is a subresource request, run these substeps:

      1. -

        Set value to the first matching statement, if any, switching on - hintName: +

        If request's client hints list is not empty, then run these + substeps for each hintName in the list: + +

          +
        1. +

          Set value to the first matching statement, if any, switching on + hintName: + +

          +
          "dpr" +
          a suitable dpr value +
          "save-data" +
          a suitable save-data value +
          "viewport-width" +
          a suitable viewport-width value +
          "width" +
          a suitable width value +
          + +
        2. Append hintName/value to + request's header list. +

        + +
      2. Let record be a new + fetch record consisting of + request and this instance of the + fetch algorithm. + +

      3. Append record to request's + client's + fetch group list of + fetch records. +

      +
    -
    -
    "dpr" -
    a suitable dpr value -
    "save-data" -
    a suitable save-data value -
    "viewport-width" -
    a suitable viewport-width value -
    "width" -
    a suitable width value -
    +
  • +

    If the ongoing fetch is terminated, then: -

  • Append hintName/value to - request's header list. - +

      +
    1. Let aborted be the termination's aborted flag. -

    2. Let record be a new - fetch record consisting of - request and this instance of the - fetch algorithm. +

    3. If aborted is set, then return an aborted network error. -

    4. Append record to request's - client's - fetch group list of - fetch records. +

    5. Return a network error.

  • Return the result of performing a main fetch @@ -2432,81 +2484,98 @@ with a CORS flag and recursive flag, run these steps:

    1. Let response be null. -

    2. If request's local-URLs-only flag is set and - request's current url is - not local, set - response to a network error. +

    3. +

      Run these steps, but abort if the ongoing fetch is terminated:

      -
    4. Execute Report Content Security Policy violations for request. - [[!CSP]] +

        -
      1. Upgrade request to a potentially secure URL, if appropriate. - [[!UPGRADE]] +

      2. If request's local-URLs-only flag is set and + request's current url is + not local, set + response to a network error. -

      3. If - should fetching request be blocked due to a bad port, - should fetching request be blocked as mixed content, - or - should fetching request be blocked by Content Security Policy - returns blocked, set response to a - network error. - [[!MIX]] - [[!CSP]] +

      4. Execute Report Content Security Policy violations for request. + [[!CSP]] -

      5. If request's referrer policy is the empty string and - request's client is non-null, then set request's - referrer policy to request's client's - referrer policy. - [[!REFERRER]] +

      6. Upgrade request to a potentially secure URL, if appropriate. + [[!UPGRADE]] -

      7. -

        If request's referrer policy - is the empty string, then set request's - referrer policy to - "no-referrer-when-downgrade". +

      8. If + should fetching request be blocked due to a bad port, + should fetching request be blocked as mixed content, + or + should fetching request be blocked by Content Security Policy + returns blocked, set response to a + network error. + [[!MIX]] + [[!CSP]] -

        We use "no-referrer-when-downgrade" because it is the - historical default. +

      9. If request's referrer policy is the empty string and + request's client is non-null, then set request's + referrer policy to request's client's + referrer policy. + [[!REFERRER]] -

      10. -

        If request's referrer - is not "no-referrer", set request's - referrer to the result of invoking - determine request's referrer. - [[!REFERRER]] +

      11. +

        If request's referrer policy + is the empty string, then set request's + referrer policy to + "no-referrer-when-downgrade". -

        As stated in Referrer Policy, user agents can - provide the end user with options to override request's - referrer to "no-referrer" or - have it expose less sensitive information. +

        We use "no-referrer-when-downgrade" because it is the + historical default. -

      12. -

        If request's current URL's scheme is - "ftp", request's client's - creation URL's scheme is not "ftp", and - request's reserved client is either null or an environment - whose target browsing context is a nested browsing context, then set - response to a network error. +

      13. +

        If request's referrer + is not "no-referrer", set request's + referrer to the result of invoking + determine request's referrer. + [[!REFERRER]] -

      14. -

        Set request's current url's - scheme to "https" if - all of the following conditions are true: +

        As stated in Referrer Policy, user agents can + provide the end user with options to override request's + referrer to "no-referrer" or + have it expose less sensitive information. -

        - +
      15. +

        If request's current URL's scheme is + "ftp", request's client's + creation URL's scheme is not "ftp", and + request's reserved client is either null or an environment + whose target browsing context is a nested browsing context, then + set response to a network error. + +

      16. +

        Set request's current url's + scheme to "https" if + all of the following conditions are true: + +

        + +
      + +
    5. +

      If the ongoing fetch is terminated, then: + +

        +
      1. Let aborted be the termination's aborted flag. + +

      2. If aborted is set, then return an aborted network error. + +

      3. Return a network error. +

    6. If request's synchronous flag is unset and recursive flag is unset, run the remaining steps @@ -2696,13 +2765,11 @@ with a CORS flag and recursive flag, run these steps:

    7. Wait for response's body. -

    8. If response does not have a - termination reason and - response does not +

    9. If response's body's stream has not + errored, and response does not match - request's integrity metadata, - set response and internalResponse to a - network error. + request's integrity metadata, set response and + internalResponse to a network error. [[!SRI]]

    @@ -2741,11 +2808,14 @@ with a CORS flag and recursive flag, run these steps:
  • Queue a fetch task on request to process response end-of-body for response. -

  • Wait for internalResponse's trailer, - if any. See +

  • Wait for either internalResponse's trailer, + if any, or for the ongoing fetch to terminate. See section 4.1.2 of [[!HTTP]]. +

  • If the ongoing fetch is terminated, then set internalResponse's + trailer failed flag. +

  • Set request's done flag.

  • Queue a fetch task on request to process response done @@ -2788,44 +2858,56 @@ steps:

    "blob"
      -
    1. Let blob be request's - current url's - object. -

    2. -

      If request's method is not - `GET` or blob is null, then return a - network error. +

      Run these steps, but abort if the ongoing fetch is terminated: -

      The `GET` method restriction - serves no useful purpose other than being interoperable. +

        +
      1. Let blob be request's + current url's + object. -

      2. Let response be a new - response. +

      3. +

        If request's method is not + `GET` or blob is null, then return a + network error. -

      4. Append - `Content-Length`/blob's - {{Blob/size}} attribute value to - response's - header list. +

        The `GET` method restriction + serves no useful purpose other than being interoperable. -

      5. Append - `Content-Type`/blob's - {{Blob/type}} attribute value to - response's - header list. +

      6. Let response be a new + response. -

      7. Set response's - HTTPS state to request's - client's HTTPS state - if request's client is non-null. +

      8. Append + `Content-Length`/blob's + {{Blob/size}} attribute value to + response's + header list. -

      9. Set response's body to - the result of performing the read operation on - blob. - +

      10. Append + `Content-Type`/blob's + {{Blob/type}} attribute value to + response's + header list. -

      11. Return response. +

      12. Set response's + HTTPS state to request's + client's HTTPS state + if request's client is non-null. + +

      13. Set response's body to + the result of performing the read operation on + blob. + + + +

      14. Return response. +

      + +
    3. Let aborted be the termination's aborted flag. + +

    4. If aborted is set, then return an aborted network error. + +

    5. Return a network error.

    "data" @@ -2936,8 +3018,7 @@ optional CORS flag and CORS-preflight flag, run these steps: url list has more than one item. -
  • Execute - set response's CSP list +

  • Execute set response's CSP list on actualResponse. [[!CSP]] @@ -3177,278 +3258,293 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b

    1. Let httpRequest be null. -

    2. If request's window is "no-window" and - request's redirect mode is "error", then set - httpRequest to request. -

    3. -

      Otherwise, run these substeps: +

      Run these steps, but abort if the ongoing fetch is terminated:

        -
      1. Set httpRequest to a copy of request except for its - body. +

      2. If request's window is "no-window" and + request's redirect mode is "error", then set + httpRequest to request. -

      3. Let body be request's body. +

      4. +

        Otherwise, run these substeps: -

      5. Set httpRequest's body to body. +

          +
        1. Set httpRequest to a copy of request except for its + body. -

        2. If body is non-null, then set request's body to a - new body whose stream is null and whose source is - body's source. -

        +
      6. Let body be request's body. -

        request is copied as httpRequest here as we need - to be able to add headers to httpRequest and read its body without - affecting request. Namely, request can be reused with redirects, - authentication, and proxy authentication. We copy rather than clone in order to reduce memory - consumption. In case request's body's source is - null, redirects and authentication will end up failing the fetch. +

      7. Set httpRequest's body to body. -

      8. -

        Let credentials flag be set if one of +

      9. If body is non-null, then set request's body to + a new body whose stream is null and whose source + is body's source. +

      - +

      request is copied as httpRequest here as we + need to be able to add headers to httpRequest and read its body + without affecting request. Namely, request can be reused with redirects, + authentication, and proxy authentication. We copy rather than clone in order to reduce memory + consumption. In case request's body's source is + null, redirects and authentication will end up failing the fetch. -

      is true, and unset otherwise. +

    4. +

      Let credentials flag be set if one of -

    5. Let contentLengthValue be null. +

      -
    6. If httpRequest's body is null and - httpRequest's method is - `POST` or `PUT`, then set contentLengthValue to - `0`. - +

      is true, and unset otherwise. -

    7. If httpRequest's body is non-null and httpRequest's - body's source is non-null, then set - contentLengthValue to httpRequest's body's - total bytes, UTF-8 encoded. +

    8. Let contentLengthValue be null. -

    9. If contentLengthValue is non-null, - append - `Content-Length`/contentLengthValue to - httpRequest's - header list. +

    10. If httpRequest's body is null and + httpRequest's method is + `POST` or `PUT`, then set contentLengthValue to + `0`. + -

    11. -

      If contentLengthValue is non-null and httpRequest's - keepalive flag is set, then: +

    12. If httpRequest's body is non-null and httpRequest's + body's source is non-null, then set + contentLengthValue to httpRequest's body's + total bytes, UTF-8 encoded. -

        -
      1. Let inflightKeepaliveBytes be zero. - -

      2. Let group be httpRequest's client's fetch group. - -

      3. Let inflightRecords be the set of fetch records in - group whose request has its - keepalive flag set and done flag unset. +

      4. If contentLengthValue is non-null, + append + `Content-Length`/contentLengthValue to + httpRequest's + header list.

      5. -

        For each fetchRecord in inflightRecords: +

        If contentLengthValue is non-null and httpRequest's + keepalive flag is set, then:

          -
        1. Let inflightRequest be fetchRecord's - request. +

        2. Let inflightKeepaliveBytes be zero. -

        3. Increment inflightKeepaliveBytes by inflightRequest's - body's total bytes. -

        +
      6. Let group be httpRequest's client's fetch group. -

      7. If the sum of contentLengthValue and inflightKeepaliveBytes is - greater than 64 kibibytes, then return a network error. -

      +
    13. Let inflightRecords be the set of fetch records in + group whose request has its + keepalive flag set and done flag unset. -

      The above limit ensures that requests that are allowed to outlive the - environment settings object and contain a body, have a bounded size and are not allowed to - stay alive indefinitely. - -

    14. If httpRequest's referrer is a URL, then - append `Referer`/httpRequest's - referrer, serialized and UTF-8 encoded, to - httpRequest's header list. - - -

    15. If the CORS flag is set, httpRequest's method is - neither `GET` nor `HEAD`, or httpRequest's - mode is "websocket", then append - `Origin`/httpRequest's origin, - serialized and UTF-8 encoded, to - httpRequest's header list. - +

    16. +

      For each fetchRecord in inflightRecords: -

    17. If httpRequest's header list - does not contain `User-Agent`, then user agents should - append - `User-Agent`/default `User-Agent` value - to httpRequest's header list. +

        +
      1. Let inflightRequest be fetchRecord's + request. -

      2. If httpRequest's cache mode is "default" and - httpRequest's header list contains - `If-Modified-Since`, - `If-None-Match`, - `If-Unmodified-Since`, - `If-Match`, or - `If-Range`, then set httpRequest's - cache mode to "no-store". +

      3. Increment inflightKeepaliveBytes by inflightRequest's + body's total bytes. +

      -
    18. If httpRequest's cache mode is "no-cache" and - httpRequest's header list does not contain - `Cache-Control`, then append - `Cache-Control`/`max-age=0` to - httpRequest's header list. +

    19. If the sum of contentLengthValue and inflightKeepaliveBytes is + greater than 64 kibibytes, then return a network error. +

    -
  • -

    If httpRequest's cache mode is - "no-store" or "reload", run these substeps: +

    The above limit ensures that requests that are allowed to outlive the + environment settings object and contain a body, have a bounded size and are not allowed + to stay alive indefinitely. -

      -
    1. If httpRequest's header list - does not contain `Pragma`, then - append `Pragma`/`no-cache` to +

    2. If httpRequest's referrer is a URL, then + append `Referer`/httpRequest's + referrer, serialized and UTF-8 encoded, to httpRequest's header list. + + +

    3. If the CORS flag is set, httpRequest's method is + neither `GET` nor `HEAD`, or httpRequest's + mode is "websocket", then append + `Origin`/httpRequest's origin, + serialized and UTF-8 encoded, to + httpRequest's header list. +

    4. If httpRequest's header list - does not contain `Cache-Control`, then - append `Cache-Control`/`no-cache` to + does not contain `User-Agent`, then user agents should + append + `User-Agent`/default `User-Agent` value + to httpRequest's header list. + +

    5. If httpRequest's cache mode is "default" and + httpRequest's header list contains + `If-Modified-Since`, + `If-None-Match`, + `If-Unmodified-Since`, + `If-Match`, or + `If-Range`, then set httpRequest's + cache mode to "no-store". + +

    6. If httpRequest's cache mode is "no-cache" and + httpRequest's header list does not contain + `Cache-Control`, then append + `Cache-Control`/`max-age=0` to httpRequest's header list. - -

    - -
  • -

    Modify httpRequest's - header list per HTTP. - -

    It would be great if we could make this more normative - somehow. At this point headers such as - `Accept-Encoding`, - `Connection`, - `DNT`, and - `Host`, - are to be appended if necessary. - -

    `Accept`, - `Accept-Charset`, and - `Accept-Language` must not be included at this point. - -

    `Accept` and - `Accept-Language` are already included (unless - fetch() is used, which does not include the latter by - default), and `Accept-Charset` is a waste of bytes. See - HTTP header layer division for more details. - -

  • -

    If credentials flag is set, run these substeps: -

    1. -

      If the user agent is not configured to block cookies for httpRequest (see - section 7 of - [[!COOKIES]]), then run these substeps: +

      If httpRequest's cache mode is + "no-store" or "reload", run these substeps:

        -
      1. Let cookies be the result of running the "cookie-string" algorithm (see - section 5.4 of - [[!COOKIES]]) with the user agent's cookie store and - httpRequest's current url. +

      2. If httpRequest's header list + does not contain `Pragma`, then + append `Pragma`/`no-cache` to + httpRequest's header list. -

      3. If cookies is not the empty string, append - `Cookie`/cookies to httpRequest's - header list. +
      4. If httpRequest's header list + does not contain `Cache-Control`, then + append `Cache-Control`/`no-cache` to + httpRequest's header list. +

      -
    2. If httpRequest's header list - contains `Authorization`, then terminate these substeps. - - -

    3. Let authorizationValue be null. - -

    4. If there's an authentication entry for httpRequest - and either httpRequest's - use-URL-credentials flag is - unset or httpRequest's - current url does not - include credentials, set - authorizationValue to authentication entry. - - -

    5. Otherwise, if httpRequest's - current url does - include credentials and authentication-fetch flag is - set, then set authorizationValue to httpRequest's - current url, - converted to an `Authorization` value. - -

    6. If authorizationValue is non-null, - append - `Authorization`/authorizationValue to - httpRequest's - header list. -

    +
  • +

    Modify httpRequest's + header list per HTTP. + +

    It would be great if we could make this more normative + somehow. At this point headers such as + `Accept-Encoding`, + `Connection`, + `DNT`, and + `Host`, + are to be appended if necessary. + +

    `Accept`, + `Accept-Charset`, and + `Accept-Language` must not be included at this point. + +

    `Accept` and + `Accept-Language` are already included (unless + fetch() is used, which does not include the latter by + default), and `Accept-Charset` is a waste of bytes. See + HTTP header layer division for more details. -

  • -

    If there's a proxy-authentication entry, use it as appropriate. +

  • +

    If credentials flag is set, run these substeps: -

    This intentionally does not depend on - httpRequest's - credentials mode. +

      +
    1. +

      If the user agent is not configured to block cookies for httpRequest (see + section 7 of + [[!COOKIES]]), then run these substeps: + +

        +
      1. Let cookies be the result of running the "cookie-string" algorithm (see + section 5.4 of + [[!COOKIES]]) with the user agent's cookie store and + httpRequest's current url. + +

      2. If cookies is not the empty string, append + `Cookie`/cookies to httpRequest's + header list. +
      + +
    2. If httpRequest's header list + contains `Authorization`, then terminate these substeps. + + +

    3. Let authorizationValue be null. + +

    4. If there's an authentication entry for httpRequest + and either httpRequest's + use-URL-credentials flag is + unset or httpRequest's + current url does not + include credentials, set + authorizationValue to authentication entry. + + +

    5. Otherwise, if httpRequest's + current url does + include credentials and authentication-fetch flag is + set, then set authorizationValue to httpRequest's + current url, + converted to an `Authorization` value. + +

    6. If authorizationValue is non-null, + append + `Authorization`/authorizationValue to + httpRequest's + header list. +

    -
  • Let response and storedResponse be null. +

  • +

    If there's a proxy-authentication entry, use it as appropriate. -

  • Let the revalidatingFlag be unset. +

    This intentionally does not depend on + httpRequest's + credentials mode. -

  • -

    If httpRequest's cache mode is neither "no-store" - nor "reload", run these substeps: +

  • Let response and storedResponse be null. + +

  • Let the revalidatingFlag be unset. -

    1. -

      Set storedResponse to the result of selecting a response from the HTTP cache, - possibly needing validation, as per the - "Constructing Responses from Caches" - chapter of HTTP Caching [[!HTTP-CACHING]], if any. +

      If httpRequest's cache mode is neither "no-store" + nor "reload", run these substeps: -

    2. If storedResponse is null, then abort these substeps. +

        +
      1. Set storedResponse to the result of selecting a response from the HTTP cache, + possibly needing validation, as per the + "Constructing Responses from Caches" + chapter of HTTP Caching [[!HTTP-CACHING]], if any. - -

      2. If storedResponse requires validation (i.e., it is not fresh), then set the - revalidatingFlag. +

      3. If storedResponse is null, then abort these substeps. -

      4. -

        If httpRequest's cache mode is "force-cache" or - "only-if-cached", then set response to storedResponse and - abort these substeps. + +

      5. If storedResponse requires validation (i.e., it is not fresh), then set the + revalidatingFlag. -

        As mandated by HTTP, this still takes the `Vary` header - into account. - -

      6. -

        If the revalidatingFlag is set, then: +

      7. +

        If httpRequest's cache mode is "force-cache" or + "only-if-cached", then set response to storedResponse and + abort these substeps. -

          -
        1. If storedResponse's header list - contains `ETag`, then append - `If-None-Match` with its value to httpRequest's - header list. +

          As mandated by HTTP, this still takes the `Vary` + header into account. -

        2. If storedResponse's header list - contains `Last-Modified`, then - append `If-Modified-Since` with its value to - httpRequest's header list. +

        3. +

          If the revalidatingFlag is set, then: + +

            +
          1. If storedResponse's header list + contains `ETag`, then append + `If-None-Match` with its value to httpRequest's + header list. + +

          2. If storedResponse's header list + contains `Last-Modified`, then + append `If-Modified-Since` with its value to + httpRequest's header list. +

          + +

          See also the + "Sending a Validation Request" + chapter of HTTP Caching [[!HTTP-CACHING]]. + +

        4. Otherwise, if the revalidatingFlag is unset, then set response to + storedResponse.

        +
      + +
    3. +

      If the ongoing fetch is terminated, then: + +

        +
      1. Let aborted be the termination's aborted flag. -

        See also the - "Sending a Validation Request" - chapter of HTTP Caching [[!HTTP-CACHING]]. +

      2. If aborted is set, then return an aborted network error. -

      3. Otherwise, if the revalidatingFlag is unset, then set response to - storedResponse. +

      4. Return a network error.

    4. @@ -3534,6 +3630,17 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b authentication-fetch flag is set, then run these subsubsteps:
        +
      1. +

        If the ongoing fetch is terminated, then: + +

          +
        1. Let aborted be the termination's aborted flag. + +

        2. If aborted is set, then return an aborted network error. + +

        3. Return a network error. +

        +
      2. Let username and password be the result of prompting the end user for a username and password, respectively, in request's window. @@ -3561,6 +3668,17 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b

      3. Needs testing: multiple `Proxy-Authenticate` headers, missing, parsing issues. +

      4. +

        If the ongoing fetch is terminated, then: + +

          +
        1. Let aborted be the termination's aborted flag. + +

        2. If aborted is set, then return an aborted network error. + +

        3. Return a network error. +

        +
      5. Prompt the end user as appropriate in request's window and store the result as a @@ -3590,6 +3708,8 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b

        1. Let credentials be true if credentials flag is set, and false otherwise. +

        2. Let response be null. +

        3. Switch on request's mode: @@ -3606,70 +3726,85 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b origin and credentials. -

        4. If connection is failure, return a - network error. - -

        5. If connection is not an HTTP/2 connection, request's - body is non-null, and request's body's - source is null, then append - `Transfer-Encoding`/`chunked` to request's - header list.

        6. -

          Let response be the result of making an HTTP request over connection - using request with the following caveats: +

          Run these steps, but abort if the ongoing fetch is terminated:

          -
            -
          • Follow the relevant requirements from HTTP. [[!HTTP]] [[!HTTP-SEMANTICS]] [[!HTTP-COND]] [[!HTTP-CACHING]] [[!HTTP-AUTH]] +

              +
            1. If connection is failure, return a + network error. -

            2. Wait until all the headers are transmitted or - fetch is being - terminated with reason reason. If - fetch is being - terminated, then set response's - termination reason to reason. +

            3. If connection is not an HTTP/2 connection, request's + body is non-null, and request's body's + source is null, then append + `Transfer-Encoding`/`chunked` to request's + header list.

            4. -

              Any responses whose - status is in the range 100 to - 199, inclusive, and is not 101, are to be ignored. +

              Set response to the result of making an HTTP request over connection + using request with the following caveats: -

              These kind of responses are - eventually followed by a "final" response. -

          +
            +
          • Follow the relevant requirements from HTTP. [[!HTTP]] [[!HTTP-SEMANTICS]] [[!HTTP-COND]] [[!HTTP-CACHING]] [[!HTTP-AUTH]] + +

          • Wait until all the headers are transmitted. + +

          • +

            Any responses whose + status is in the range 100 to + 199, inclusive, and is not 101, are to be ignored. -

            The exact layering between Fetch and HTTP still needs to be sorted through and - therefore response represents both a response and - an HTTP response here. +

            These kind of responses are + eventually followed by a "final" response. +

          -

          If request's header list contains - `Transfer-Encoding`/`chunked` and response is transferred - via HTTP/1.0 or older, then return a network error. +

          The exact layering between Fetch and HTTP still needs to be sorted through and + therefore response represents both a response and + an HTTP response here. -

          If the HTTP request results in a TLS client certificate dialog, run these substeps: +

          If request's header list contains + `Transfer-Encoding`/`chunked` and response is transferred + via HTTP/1.0 or older, then return a network error. -

            -
          1. If request's window - is an environment settings object, make the dialog - available in request's - window. +

            If the HTTP request results in a TLS client certificate dialog, run these substeps: -

          2. Otherwise, return a network error. +

              +
            1. If request's window + is an environment settings object, make the dialog + available in request's + window. + +

            2. Otherwise, return a network error. +

            + +

            If response was retrieved over HTTPS, set its + HTTPS state to either + "deprecated" or "modern". + [[!TLS]] + +

            The exact determination here is up to user agents for the + time being. User agents are strongly encouraged to only succeed HTTPS connections with + strong security properties and return + network errors otherwise. Using the + "deprecated" state value ought to be a temporary and last resort kind + of option. + +

            Transmit body for request.

          -

          If response was retrieved over HTTPS, set its - HTTPS state to either - "deprecated" or "modern". - [[!TLS]] +

        7. +

          If the ongoing fetch is terminated, then: + +

            +
          1. Let aborted be the termination's aborted flag. + +

          2. If connection is an HTTP/2 connection, then transmit an + "RST_STREAM" to cancel the underlying stream. -

            The exact determination here is up to user agents for the - time being. User agents are strongly encouraged to only succeed HTTPS connections with - strong security properties and return - network errors otherwise. Using the - "deprecated" state value ought to be a temporary and last resort kind - of option. +

          3. If aborted is set, then return an aborted network error. -

            Transmit body for request. +

          4. Return a network error. +

        8. Let strategy be an object. The user agent may choose any object. @@ -3677,12 +3812,11 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b

          strategy is used to control the queuing strategy of stream constructed below. -

        9. Let pull be an action that resumes the - ongoing fetch if it is suspended. +

        10. Let pull be an action that resumes the ongoing fetch + if it is suspended. -

        11. Let cancel be an action that - terminates the ongoing fetch with reason - end-user abort. +

        12. Let cancel be an action that terminates the + ongoing fetch with the aborted flag set.

        13. Let stream be the result of @@ -3691,132 +3825,160 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b pull and cancel.

          This construction operation will not throw an exception. -

        14. Set response's body to a new - body whose stream is - stream. +

        15. +

          Run these steps, but abort if the ongoing fetch is terminated:

          -
        16. If response has a payload body length, then set response's - body's - total bytes to that payload body length. - +

            +
          1. Set response's body to a new + body whose stream is + stream. -

          2. -

            Delete - `Content-Encoding` from response's - header list if one of the following - conditions is true: +

          3. If response has a payload body length, then set response's + body's + total bytes to that payload body length. + -

            +
          4. +

            Delete + `Content-Encoding` from response's + header list if one of the following + conditions is true: + +

            -

            This deals with broken Apache configurations. Ideally HTTP would define - this. - +

            This deals with broken Apache configurations. Ideally HTTP would define + this. + -

            Gecko - bug 1030660 looks - into whether this quirk can be removed. +

            Gecko + bug 1030660 looks + into whether this quirk can be removed. -

          5. Execute - set response's CSP list - on response. [[!CSP]] +

          6. Execute + set response's CSP list + on response. [[!CSP]] -

          7. If response is not a - network error and request's - cache mode is not "no-store", - update response in the HTTP cache for request. - +

          8. If response is not a + network error and request's + cache mode is not "no-store", + update response in the HTTP cache for request. + + +

          9. +

            If credentials flag is set and the user agent is not configured to block cookies for + request (see section 7 of + [[!COOKIES]]), then run the "set-cookie-string" parsing algorithm (see section 5.2 of [[!COOKIES]]) on the value of each header whose name is a + byte-case-insensitive match for `Set-Cookie` in response's header list, if any, and request's current url. + +

            This is a fingerprinting vector. +

        17. -

          If credentials flag is set and the user agent is not configured to block cookies for - request (see section 7 of - [[!COOKIES]]), then run the "set-cookie-string" parsing algorithm (see - section 5.2 of - [[!COOKIES]]) on the value - of each header whose name is a byte-case-insensitive match for - `Set-Cookie` in response's header list, if any, and - request's current url. +

          If the ongoing fetch is terminated, then: + +

            +
          1. Let aborted be the termination's aborted flag. -

            This is a fingerprinting vector. +

          2. If aborted is set, then set response's + aborted flag. + +

          3. Return response. +

        18. Run these substeps in parallel:

          1. -

            Whenever one or more bytes are transmitted from response's message body, let - bytes be the transmitted bytes and run these subsubsteps: - +

            While true, breaking if the ongoing fetch terminates:

              -
            1. Increase response's - body's - transmitted bytes with bytes' - length. +

            2. +

              If one or more bytes have been transmitted from response's message body, then: -

            3. Let codings be the result of extracting header list values given - `Content-Encoding` and response's header list. +

                +
              1. Let bytes be the transmitted bytes. -

              2. -

                Set bytes to the result of handling - content codings given codings and bytes. +

              3. Increase response's body's transmitted + bytes with bytes' length. -

                This makes the `Content-Length` - header unreliable to the extent that it was reliable - to begin with. +

              4. Let codings be the result of extracting header list values given + `Content-Encoding` and response's header list. -

              5. -

                Enqueue a Uint8Array - object wrapping an ArrayBuffer containing bytes to stream. - If that threw an exception, terminate the ongoing - fetch with fatal, error - stream with that exception and abort these subsubsteps. - -

              6. If stream doesn't need more - data and request's synchronous flag is unset, ask the user agent - to suspend the ongoing fetch. +

              7. +

                Set bytes to the result of handling content + codings given codings and bytes. + +

                This makes the `Content-Length` header + unreliable to the extent that it was reliable to begin with. + +

              8. Enqueue a Uint8Array object wrapping an + ArrayBuffer containing bytes to stream. If that threw an + exception, terminate the ongoing fetch, and + error stream with that exception. + +

              9. If stream doesn't need more + data and request's synchronous flag is unset, ask the user agent to suspend the ongoing fetch. +

              + +
            4. Otherwise, if the bytes transmission for response's message body is done + normally and stream is readable, then + close stream and abort these in-parallel steps.

            -
          2. If at any point the bytes transmission for response's message body is done - normally and stream is readable, - then close stream. - +

            The following steps can only occur if the ongoing fetch terminates. + +

          3. Let aborted be the termination's aborted flag.

          4. -

            If at any point fetch is - terminated with reason reason, - run these subsubsteps: +

            If aborted is set, then:

              -
            1. Set response's termination - reason to reason. +

            2. Set response's aborted flag. -

            3. If stream is readable, - error stream with a - TypeError. +

            4. If stream is readable, error + stream with an "AbortError" {{DOMException}}.

            + +
          5. Otherwise, if stream is readable, + error stream with a TypeError. + +

          6. If connection is an HTTP/2 connection, then transmit an + "RST_STREAM" to cancel the underlying stream. + +

          7. +

            Otherwise, the user agent should close connection unless it would be bad for + performance to do so. + +

            For instance, the user agent could keep the connection open if it knows there's + only a few bytes of transfer remaining on a reusable connection. In this case it could be worse + to close the connection and go through the handshake process again for the next fetch.

          -

          These are run in parallel - as at this point it is unclear whether response's - body is relevant (response - might be a redirect). +

          These are run in parallel as at this point it is unclear whether + response's body is relevant (response might be a + redirect). -

        19. Return response. Typically - response's body's - stream is still being enqueued to after returning. +

        20. Return response. Typically response's + body's stream is still being enqueued to after + returning.

        @@ -4066,9 +4228,12 @@ Entries may be removed before that moment arrives. request and response, run these steps:
          -
        1. Let origin be the result of extracting header list values given - `Access-Control-Allow-Origin` and response's - header list. +

        2. +

          Let origin be the result of extracting header list values given + `Access-Control-Allow-Origin` and response's + header list. + +

          The above will fail for network errors, as they have no headers.

        3. If origin is null or failure, return failure. @@ -4679,6 +4844,7 @@ interface Request { readonly attribute RequestRedirect redirect; readonly attribute DOMString integrity; readonly attribute boolean keepalive; + readonly attribute AbortSignal signal; [NewObject] Request clone(); }; @@ -4695,6 +4861,7 @@ dictionary RequestInit { RequestRedirect redirect; DOMString integrity; boolean keepalive; + AbortSignal? signal; any window; // can only be set to null }; @@ -4716,6 +4883,9 @@ omitted from RequestMode as it cannot be used nor obser

          A {{Request}} object also has an associated headers (null or a {{Headers}} object), initially null. +

          A {{Request}} object has an associated signal (an {{AbortSignal}} object), +initially a new {{AbortSignal}} object. +

          A {{Request}} object's body is its request's body. @@ -4736,6 +4906,8 @@ constructor must run these steps:

        4. Let baseURL be current settings object's API base URL. +

        5. Let signal be null. +

        6. If input is a string, then run these substeps: @@ -4766,6 +4938,8 @@ constructor must run these steps:

        7. Set request to input's request. + +

        8. Set signal to input's signal.

      6. Let origin be current settings object's @@ -4935,12 +5109,23 @@ constructor must run these steps: to method.

      +
    5. If init's signal member is present, then set signal to + it. +

    6. Let r be a new {{Request}} object associated with request.

    7. Set r's headers to a new {{Headers}} object, whose header list is request's header list, and guard is "request". +

    8. +

      If signal is not null, then + add the following abort steps to signal: + +

        +
      1. Signal abort on r's signal. +

      +
    9. Let headers be a copy of r's headers and its associated header list. @@ -5099,6 +5284,9 @@ must return request's must return true if request's keepalive flag is set, and false otherwise. +

      The signal attribute's getter must return the +associated signal. +


      The clone() method, when invoked, must @@ -5120,6 +5308,19 @@ run these steps: header list, and guard is context object's headers' guard. +

    10. If context object's signal's aborted flag + is set, set clonedRequestObject signal's + aborted flag. + +

    11. +

      Otherwise, add the following abort steps to context object's + signal: + +

        +
      1. Signal abort on clonedRequestObject + signal. +

      +
    12. Return clonedRequestObject.

    @@ -5367,11 +5568,21 @@ method, must run these steps:
    1. Let p be a new promise. -

    2. Let request be the associated - request of the result of invoking the initial value of - {{Request}} as constructor with input and - init as arguments. If this throws an exception, reject - p with it and return p. +

    3. Let requestObject be the result of invoking the initial value of {{Request}} as + constructor with input and init as arguments. If this throws an exception, + reject p with it and return p + +

    4. Let request be requestObject's request. + +

    5. +

      If requestObject's signal's aborted flag + is set, then: + +

        +
      1. Abort fetch with p, request, and null. + +

      2. Return p. +

    6. If request's client's global object is a {{ServiceWorkerGlobalScope}} object, @@ -5381,6 +5592,25 @@ method, must run these steps: {{Headers}} object whose guard is "immutable". +
    7. +

      Let locallyAborted be false. + +

      This lets us reject promises with predictable timing, when the request to abort + comes from the same thread as the call to fetch. + +

    8. +

      Add the following abort steps to requestObject's + signal: + +

        +
      1. Set locallyAborted to true. + +

      2. Abort fetch with p, request, and + responseObject. + +

      3. Terminate the ongoing fetch with the aborted flag set. +

      +
    9. Run the following in parallel: @@ -5389,9 +5619,14 @@ method, must run these steps:

      To process response for response, run these substeps:

        -
      1. If response's type is - "error", reject p with a TypeError and terminate - these substeps. +

      2. If locallyAborted is true, terminate these substeps. + +

      3. If response's aborted flag is set, then abort fetch + with p, request, and responseObject, and terminate these + substeps. + +

      4. If response is a network error, then reject p with a + TypeError and terminate these substeps.

      5. Associate responseObject with response. @@ -5401,9 +5636,25 @@ method, must run these steps:

        To process response done for response, run these substeps:

          +
        1. If locallyAborted is true, terminate these substeps. +

        2. Let trailerObject be a new {{Headers}} object whose guard is "immutable". +

        3. +

          If response's trailer failed flag is set, then: + +

            +
          1. If response's aborted flag is set, reject + responseObject's trailer promise with an + "AbortError" {{DOMException}}. + +

          2. Otherwise, reject responseObject's trailer promise with + a TypeError. + +

          3. Terminate these substeps. +

          +
        4. Associate trailerObject with response's trailer. @@ -5415,11 +5666,41 @@ method, must run these steps:

        5. Return p.

        +

        To abort fetch with a promise, request, and +responseObject, run these steps: + +

          +
        1. Let error be an "AbortError" {{DOMException}}. + +

        2. +

          Reject promise with error. + +

          This is a no-op if promise has already fulfilled. + +

        3. If request's body is not null and is + readable, then cancel request's + body with error. + +

        4. If responseObject is null, then return. + +

        5. +

          Reject responseObject's trailer promise with error. + +

          This is a no-op if responseObject's trailer promise + has already fulfilled. + +

        6. Let response be responseObject's response. + +

        7. If response's body is not null and is + readable, then error + response's body with error. +

        +

        Garbage collection

        -

        The user agent may terminate an ongoing fetch with -reason garbage collection if that termination is not observable through script. +

        The user agent may terminate an ongoing fetch with if that +termination is not observable through script.

        "Observable through script" means observable through fetch()'s arguments and return value. Other ways, such as