From 3b4cb5495389e8854279c04ebe1d89d6b078365e Mon Sep 17 00:00:00 2001 From: Ilya Grigorik Date: Fri, 24 Feb 2017 23:39:18 -0800 Subject: [PATCH] Enforce limit on inflight keepalive bytes Requests with keepalive flag set are allowed to outlive the environment settings object. We want to make sure that such requests do not negatively impact the user experience when a page is unloaded, etc. This limits the amount of (body) bytes that can be inflight at any point when the request has the keepalive flag set; this flag is also set by sendBeacon(). Background: https://github.com/w3c/beacon/pull/39. Tests: https://github.com/w3c/web-platform-tests/pull/4878. --- fetch.bs | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/fetch.bs b/fetch.bs index e5ce6d50e..63c0b6f62 100644 --- a/fetch.bs +++ b/fetch.bs @@ -3179,13 +3179,36 @@ steps: header list.
  • -

    If contentLengthValue is non-null, httpRequest's - keepalive flag is set, and contentLengthValue is greater than a - user-agent-defined maximum, then return a network error. +

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

    The above user-agent-defined maximum 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. 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. +

      For each fetchRecord in inflightRecords: + +

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

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

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

    + +

    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.

  • If httpRequest's referrer is a URL, then append `Referer`/httpRequest's @@ -4158,7 +4181,7 @@ run these steps:

    1. -

      If object is a sequence, then for each header in +

      If object is a sequence, then for each header in object, run these substeps:

        @@ -4170,8 +4193,8 @@ run these steps: headers. Rethrow any exception.
      -
    2. Otherwise, object is a record, then for each mapping - (key, value) in object, append +

    3. Otherwise, object is a record, then for each key + → value in object, append key/value to headers. Rethrow any exception.