diff --git a/fetch.bs b/fetch.bs index 9f09743e5..e35485f38 100644 --- a/fetch.bs +++ b/fetch.bs @@ -194,8 +194,74 @@ lt="authentication entry">authentication entries (for HTTP authentication).
task destination (default null)
Null, a global object, or a parallel queue. +
timing info +
A fetch timing info. +

A fetch timing info is a struct used to maintain timing information +later required by the resource timing and navigation timing specs. It has the following +items: +

+
redirect start time (default zero) +
A DOMHighResTimeStamp +
redirect end time (default zero) +
A DOMHighResTimeStamp +
fetch start time (default zero) +
A DOMHighResTimeStamp +
request start time (default zero) +
A DOMHighResTimeStamp +
response start time (default zero) +
A DOMHighResTimeStamp +
response end time (default zero) +
A DOMHighResTimeStamp +
encoded body size (default zero) +
A number. +
decoded body size (default zero) +
A number. +
connection timing info (default null) +
Null or a connection timing info. +
+ +

A connection timing info is a struct used to maintain timing +information pertaining to the process of obtaining a connection. It has the following +items: +

+
domain lookup start time (default zero) +
A DOMHighResTimeStamp +
domain lookup end time (default zero) +
A DOMHighResTimeStamp +
connection start time (default zero) +
A DOMHighResTimeStamp +
connection end time (default zero) +
A DOMHighResTimeStamp +
secure connection start time (default zero) +
A DOMHighResTimeStamp +
alpn negotiated protocol (default empty string) +
A string. +
+ +

DOMHighResTimeStamp and +unsafe shared current time +are defined in [[HR-TIME]]. + +

Note that timestamps in this spec are usually unsafe, and are meant to be coarsened +and normalized to a global object prior to being exposed. + +

To clamp connection timing info, given connection timing info +timingInfo and DOMHighResTimeStamp defaultStartTime, run these +steps: +

    +
  1. If timingInfo's connection start time is + greater than defaultStartTime, then return timingInfo. +

  2. Otherwise, return a new connection timing info, with + domain lookup start time set to defaultStartTime, + domain lookup end time set to defaultStartTime, + connection start time set to defaultStartTime, + connection end time set to defaultStartTime, + secure connection start time set to + defaultStartTime, and alpn negotiated protocol + set to timingInfo's alpn negotiated protocol. +

    To queue a fetch task, given an algorithm algorithm, a global object or a parallel queue taskDestination, run these steps: @@ -1107,8 +1173,10 @@ must be an algorithm accepting an exception.

close steps -
  1. Queue a fetch task given processEndOfBody and - taskDestination.

+
    +
  1. Queue a fetch task given processEndOfBody and + taskDestination. +

error steps, given e
  1. Queue a fetch task to run processBodyError given e, @@ -1855,6 +1923,9 @@ Unless stated otherwise, it is "default".

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

    A response can have an associated fetch timing info +timing info, initially null. +

    A response has an associated URL. It is a pointer to the last URL in response's URL list and null if @@ -2144,6 +2215,9 @@ unset or keepalive is false, termi identified by a key (a network partition key), an origin (an origin), and credentials (a boolean). +

    Each connection has an associated connection timing info +timingInfo, initially a new connection timing info. +

    To obtain a connection, given a key, origin, credentials, an optional boolean forceNew (default false), an optional boolean http3Only (default @@ -2168,15 +2242,14 @@ false), and an optional boolean dedic

  • Let connection be null. -

  • Run these steps, but abort when 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]] + origin, while recording connnection timing info for connection. + [[!HTTP]] [[!HTTP-SEMANTICS]] [[!HTTP-COND]] [[!HTTP-CACHING]] [[!HTTP-AUTH]] [[!TLS]]

      If http3Only is true, then establish an HTTP/3 connection. [[!HTTP3]] @@ -2215,6 +2288,86 @@ clearly stipulates that connections are keyed on +

      When recording connnection timing info given a connection, perform the +following steps: +

        +
      1. Let timingInfo be connection's timingInfo. +

      2. If the domain information is available in cache, then set timingInfo's +domain lookup start time to the result of calling +unsafe shared current time immmediately after beginning retrieval of the +information from cache. +
      3. Otherwise, set timingInfo's +domain lookup start time to the result of calling +unsafe shared current time immmediately before starting the domain lookup. +
      4. If the domain information is available in cache, then set timingInfo's +domain lookup end time to the result of calling +unsafe shared current time immmediately after retrieving the information from +cache. +
      5. Otherwise, set timingInfo's +domain lookup end time to the result of calling +unsafe shared current time immmediately after finishing the domain lookup. +
      6. Set timingInfo's +connection start time to the result of calling +unsafe shared current time immmediately before establishing the connection to +the server or proxy. +
      7. Set timingInfo's +connection end time to the result of calling +unsafe shared current time immmediately after establishing the connection to the +server or proxy, as follows: +
          +
        • The returned time MUST include the time interval to establish the transport + connection, as well as other time intervals such as SOCKS authentication. It + MUST include the time interval to complete enough of the TLS handshake to + request the resource.
        • +
        • If the user agent used TLS False Start [[RFC7918]] for this connection, + this interval MUST NOT include the time needed to receive the server's + Finished message.
        • +
        • If the user agent sends the request with early data [[RFC8470]] without + waiting for the full handshare to complete, this interval MUST NOT include + the time needed to receive the server's ServerHello message.
        • +
        • If the user agent waits for full handshake completion to send the + request, this interval includes the full TLS handshake even if other + requests were sent using early data on this connection.
        • +
        + +

        Example: Suppose the user agent establishes an HTTP/2 connection + over TLS 1.3 to send a GET request and a POST request. It sends the ClientHello + at time t1 and then sends the GET request with early data. The + POST request is not safe [[HTTP-SEMANTICS]] (section 4.2.1), so the user agent waits + to complete the handshake at time t2 before sending it. Although + both requests used the same connection, the GET request reports a connectEnd + value of t1, while the POST request reports a connectEnd value for + t2.

        + +
      8. If a secure transport is used, set timingInfo's +secure connection start time to the result of calling +unsafe shared current time immmediately before starting the handshake process to +secure connection. [[!TLS]] +
      9. Set timingInfo's alpn negotiated protocol +to the connection's ALPN Protocol ID as specified in [[RFC7301]], with the +following caveats: +
          +
        • When a proxy is configured, if a tunnel connection is established then this attribute + MUST return the ALPN Protocol ID of the tunneled protocol, otherwise it MUST return the ALPN + Protocol ID of the first hop to the proxy. +

        • Octets in the ALPN protocol MUST NOT be percent-encoded if they are valid token + characters except "%", and when using percent-encoding, uppercase hex digits MUST be used. +

        • Formally registered ALPN protocol IDs are documented by + IANA. +

        • In case the user agent is using an experimental, non-registered protocol, the user + agent MUST use the ALPN negotiated value if any. If ALPN was not used for protocol + negotiations, the user agent MAY use another descriptive string. +

          The "h3" ALPN ID is defined for the final version + of the HTTP/3 protocol in the + HTTP/3 + Internet Draft. +

          Note that alpn negotiated protocol is + intended to identify the network protocol in use for the fetch regardless of how it was + actually negotiated; that is, even if ALPN is not used to negotiate the network protocol, + this attribute still uses the ALPN Protocol IDs to indicate the protocol in use. +

        +

      Network partition keys

      @@ -3351,6 +3504,7 @@ the request.
    2. Let fetchParams be a new fetch params whose request is request, + timing info is a new fetch timing info, process request body is processRequestBody, process request end-of-body is processRequestEndOfBody, process response is processResponse, @@ -3439,6 +3593,10 @@ steps:

    3. Let response be null. +

    4. Set fetchParams's timing info's + fetch start time to the result of calling + unsafe shared current time. +

    5. If request's local-URLs-only flag is set and request's current URL is not local, then set response to a network error. @@ -3763,11 +3921,41 @@ steps:

    6. Wait for either response's body to be null, or response's body's stream to be - closed or errored, and then set - request's done flag. - + closed or errored, and perform the following steps: +

        +
      1. Set request's done flag. + +

    +

    To handle response end, given fetch params fetchParams and +response response, perform the following steps: +

      +
    1. Set fetchParams's timing info's + response end time to the unsafe shared current time. +
    2. Let request be fetchParams's request. +
    3. Let globalObject be request's + client's global object. +
    4. Let timingInfo be fetchParams's timing info. +
    5. Let requestedURL be response's URL list's first + item. +
    6. Return, if request's destination is one of the following: +
        +
      • "report" +
      • "document" +
      • "frame" +
      + +
    7. If response's timing allow passed flag is not set, set + timingInfo to a new fetch timing info, with its + fetch start time set to timingInfo's + fetch start time, + and response end time set to timingInfo's + response end time. +

      TODO: enqueue in [[resource-timing]] with timingInfo, + requestedURL and globalObject. See + Issue #252. +

    Scheme fetch

    @@ -3891,6 +4079,8 @@ these steps:
  • Let actualResponse be null. +

  • Let timingInfo be fetchParams's timing info +

  • If request's service-workers mode is "all", then: @@ -4031,8 +4221,9 @@ these steps: internal response is actualResponse.

    "follow" -

    Set response to the result of running HTTP-redirect fetch given - fetchParams and response. +

    Set timingInfo's redirect start time to + timingInfo's fetch start time, and set response to + the result of running HTTP-redirect fetch given fetchParams and response. @@ -4122,6 +4313,9 @@ run these steps:

    request's body's source's nullity has already been checked. +

  • Set fetchParams's timing info's + redirect end time to the unsafe shared current time. +

  • Append locationURL to request's URL list. @@ -4710,6 +4904,8 @@ optional boolean forceNewConnection (default false), run these steps:

  • Let response be null. +

  • Let timingInfo be fetchParams's timing info. +

  • Let httpCache be the result of determining the HTTP cache partition, given httpRequest. @@ -4735,6 +4931,11 @@ optional boolean forceNewConnection (default false), run these steps: includeCredentials, and forceNewConnection. +

  • Set timingInfo's connection timing info to the result + of calling clamp connection timing info with connection's + timingInfo and timingInfo's + fetch start time. +
  • Run these steps, but abort when the ongoing fetch is terminated: @@ -4748,6 +4949,9 @@ optional boolean forceNewConnection (default false), run these steps: `Transfer-Encoding`/`chunked` to request's header list. +

  • Set timingInfo's request start time to + unsafe shared current time. +
  • Set response to the result of making an HTTP request over connection using request with the following caveats: @@ -4773,6 +4977,9 @@ optional boolean forceNewConnection (default false), run these steps: `Transfer-Encoding`/`chunked` and response is transferred via HTTP/1.0 or older, then return a network error. +

  • Set timingInfo's response start time to + the unsafe shared current time. +

    If the HTTP request results in a TLS client certificate dialog, then:

      @@ -4874,6 +5081,8 @@ optional boolean forceNewConnection (default false), run these steps: highWaterMark, and sizeAlgorithm set to sizeAlgorithm. +
    1. Let timingInfo be the fetchParams's timing info. +

    2. Run these steps, but abort when the ongoing fetch is terminated: @@ -4938,6 +5147,12 @@ optional boolean forceNewConnection (default false), run these steps:

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

    4. Increase timingInfo's encoded body size + by bytes's length. + +

      TODO: add tests to verify that this works in the case where the + `Content-Length` headercontent-length is missing or incorrect. +

    5. Set bytes to the result of handling content codings given codings and bytes. @@ -4945,6 +5160,9 @@ optional boolean forceNewConnection (default false), run these steps:

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

    6. Increase timingInfo's decoded body size by + bytes's length. +

    7. If bytes is failure, then terminate the ongoing fetch. @@ -4960,10 +5178,10 @@ optional boolean forceNewConnection (default false), run these steps:

    8. 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. + close stream, Call handle response end + with fetchParams and response, and abort these in-parallel steps.

    -
  • If aborted, then: @@ -4974,8 +5192,13 @@ optional boolean forceNewConnection (default false), run these steps:

    If aborted is set, then:

      +
    1. Call handle response end with fetchParams and response. +

    2. Set response's aborted flag. +

    3. Set timingInfo's response end time to + the unsafe shared current time. +

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