From a39c70507f56be2fc979a1d49516dbaf45a0deb7 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 10:16:18 +0100 Subject: [PATCH 01/15] Assert range is valid --- fetch.bs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fetch.bs b/fetch.bs index a1d323376..552625fa4 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1847,6 +1847,9 @@ is to return the result of serializing a request origin with request last, run these steps:
    +
  1. Assert: last is not given, or first is less than or equal to + last. +

  2. Let rangeValue be `bytes `.

  3. Serialize and isomorphic encode first, From e0b0a28e549be5b3b9c91d1a26472ec4db00f817 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 10:16:36 +0100 Subject: [PATCH 02/15] =?UTF-8?q?Move=20early=20exit=E2=80=A6=20earlier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fetch.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fetch.bs b/fetch.bs index 552625fa4..fb8b739c6 100644 --- a/fetch.bs +++ b/fetch.bs @@ -770,6 +770,9 @@ production as

    1. Let value be header's value. +

    2. If value's length is greater than 128, then return + false. +

    3. Byte-lowercase header's name and switch on the result: @@ -826,9 +829,6 @@ fetch("https://victim.example/naïve-endpoint", {

      Return false. -

    4. If value's length is greater than 128, then return - false. -

    5. Return true.

    From 482eaf1430547c346bdb50e024bdffae28ccc8e0 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 10:17:00 +0100 Subject: [PATCH 03/15] Allow 'simple' range header values without preflight --- fetch.bs | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/fetch.bs b/fetch.bs index fb8b739c6..0dad4ffe5 100644 --- a/fetch.bs +++ b/fetch.bs @@ -825,6 +825,9 @@ fetch("https://victim.example/naïve-endpoint", { +
    `Range` +

    If value is not a simple range header value, then return false. +

    Otherwise

    Return false. @@ -1038,6 +1041,75 @@ run these steps:

  4. Return values.

+

To determine if a byte sequence value is a +simple range header value, perform the following steps. They return a boolean. + +

    +
  1. If value does not start with + `bytes `, then return false. + +

  2. If the 6th byte of value is not in the range 0x30 (0) to 0x39 (9), + inclusive, then return false. + +

  3. Let rangeStartBytes be the 6th byte of value. + +

  4. Let rangeEndBytes be an empty byte sequence. + +

  5. Let state be "rangeStart". + +

  6. Let i be 7. + +

  7. +

    While i is less than value's length: + +

      +
    1. +

      Switch on state: + +

      +
      "rangeStart" +
      +
        +
      1. If the ith byte of value is 0x2D (-), then set + state to "rangeEnd". + +

      2. +

        Otherwise: + +

          +
        1. If the ith byte of value is not in the range 0x30 (0) + to 0x39 (9), inclusive, then return false. + +

        2. Append the ith byte of value to + rangeStartBytes. +

        +
      + +
      "rangeEnd" +
      +
        +
      1. If the ith byte of value is not in the range 0x30 (0) to + 0x39 (9), inclusive, then return false. + +

      2. Append the ith byte of value to rangeEndBytes. +

      +
      + +
    2. Increment i. +

    + +
  8. If rangeEndBytes's length is 0, then return true. + +
  9. If rangeStartBytes, parsed as an integer, is greater than + rangeEndBytes, parsed as an integer, then return false. + +

  10. Return true. +

+ +

A simple range header value is a subset of allowed range header values, but +it's the most common form used by user agents when requesting media or resuming downloads. This +format of range header value can be set using add a range header. +


A default `User-Agent` value is a From d8eb7ee453d81686263a6a9945f34003ff233124 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 10:39:47 +0100 Subject: [PATCH 04/15] No longer need link text --- fetch.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fetch.bs b/fetch.bs index 0dad4ffe5..f2a00154d 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1045,8 +1045,8 @@ run these steps: simple range header value, perform the following steps. They return a boolean.

    -
  1. If value does not start with - `bytes `, then return false. +

  2. If value does not start with `bytes `, + then return false.

  3. If the 6th byte of value is not in the range 0x30 (0) to 0x39 (9), inclusive, then return false. From 4ef481d1df6b5d44278395bba41c78390da54849 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 10:53:29 +0100 Subject: [PATCH 05/15] Ensure `-` is included --- fetch.bs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fetch.bs b/fetch.bs index f2a00154d..0be10b3fe 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1098,7 +1098,9 @@ run these steps:

  4. Increment i.

-
  • If rangeEndBytes's length is 0, then return true. +
  • If state is not "rangeEnd", then return false. + +

  • If rangeEndBytes's length is 0, then return true.

  • If rangeStartBytes, parsed as an integer, is greater than rangeEndBytes, parsed as an integer, then return false. From f987f4a0c19405816b7fb7374c1d90b4ffb1fd35 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 11:50:55 +0100 Subject: [PATCH 06/15] Simplify parsing using code point collection --- fetch.bs | 61 ++++++++++---------------------------------------------- 1 file changed, 10 insertions(+), 51 deletions(-) diff --git a/fetch.bs b/fetch.bs index 0be10b3fe..81ff20294 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1045,65 +1045,24 @@ run these steps: simple range header value, perform the following steps. They return a boolean.

      -
    1. If value does not start with `bytes `, - then return false. +

    2. Let data be the isomorphic decoding of value. -

    3. If the 6th byte of value is not in the range 0x30 (0) to 0x39 (9), - inclusive, then return false. +

    4. If data does not start with "bytes ", then return false. -

    5. Let rangeStartBytes be the 6th byte of value. +

    6. Let position be a position variable for data, initially pointing at the 6th code point of data. -

    7. Let rangeEndBytes be an empty byte sequence. +

    8. Let rangeStart be the result of collecting a sequence of code points that are in the range U+0030 (0) to U+0039 (9), inclusive, from data given position. -

    9. Let state be "rangeStart". +

    10. If the code point at position within data is not U+002D (-), then return false. -

    11. Let i be 7. - -

    12. -

      While i is less than value's length: - -

        -
      1. -

        Switch on state: - -

        -
        "rangeStart" -
        -
          -
        1. If the ith byte of value is 0x2D (-), then set - state to "rangeEnd". - -

        2. -

          Otherwise: - -

            -
          1. If the ith byte of value is not in the range 0x30 (0) - to 0x39 (9), inclusive, then return false. - -

          2. Append the ith byte of value to - rangeStartBytes. -

          -
        - -
        "rangeEnd" -
        -
          -
        1. If the ith byte of value is not in the range 0x30 (0) to - 0x39 (9), inclusive, then return false. - -

        2. Append the ith byte of value to rangeEndBytes. -

        -
        - -
      2. Increment i. -

      +
    13. Advance position by 1. -

    14. If state is not "rangeEnd", then return false. +

    15. Let rangeEnd be the result of collecting a sequence of code points that are in the range U+0030 (0) to U+0039 (9), inclusive, from data given position. -

    16. If rangeEndBytes's length is 0, then return true. +

    17. If rangeEnd's length is 0, then return true. -

    18. If rangeStartBytes, parsed as an integer, is greater than - rangeEndBytes, parsed as an integer, then return false. +

    19. If rangeStart, parsed as an integer, is greater than rangeEnd, parsed + as an integer, then return false.

    20. Return true.

    From 9db2a6525827bc2c3b7d00dbb0c1e73cdcebbfe5 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 12:00:16 +0100 Subject: [PATCH 07/15] Add note about missing end value --- fetch.bs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fetch.bs b/fetch.bs index 81ff20294..6f379ad54 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1059,7 +1059,10 @@ run these steps:
  • Let rangeEnd be the result of collecting a sequence of code points that are in the range U+0030 (0) to U+0039 (9), inclusive, from data given position. -

  • If rangeEnd's length is 0, then return true. +

  • +

    If rangeEnd's length is 0, then return true. + +

    The range end can be omitted, e.g., `bytes 0-` is valid.

  • If rangeStart, parsed as an integer, is greater than rangeEnd, parsed as an integer, then return false. From dc0ee1cf076334275548b0ce6a6c932dba6c7433 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 12:45:24 +0100 Subject: [PATCH 08/15] Update fetch.bs Co-authored-by: Anne van Kesteren --- fetch.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fetch.bs b/fetch.bs index 6f379ad54..01a0e6126 100644 --- a/fetch.bs +++ b/fetch.bs @@ -825,7 +825,7 @@ fetch("https://victim.example/naïve-endpoint", { -

    `Range` +
    `range`

    If value is not a simple range header value, then return false.

    Otherwise From c54b56fcee650cbf1235aa9dbafb0924a57b9d8a Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 12:54:34 +0100 Subject: [PATCH 09/15] It's `bytes=` --- fetch.bs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fetch.bs b/fetch.bs index 01a0e6126..9ffe6e247 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1047,7 +1047,8 @@ run these steps:
    1. Let data be the isomorphic decoding of value. -

    2. If data does not start with "bytes ", then return false. +

    3. If data does not start with "bytes=", then return + false.

    4. Let position be a position variable for data, initially pointing at the 6th code point of data. @@ -1886,7 +1887,7 @@ is to return the result of serializing a request origin with request

    5. Assert: last is not given, or first is less than or equal to last. -

    6. Let rangeValue be `bytes `. +

    7. Let rangeValue be `bytes=`.

    8. Serialize and isomorphic encode first, and append the result to rangeValue. From 59a73801f1152e37bbba151ac6ebc1b36df3a853 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 12:55:13 +0100 Subject: [PATCH 10/15] Check for end of value --- fetch.bs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fetch.bs b/fetch.bs index 9ffe6e247..ab963274b 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1060,6 +1060,8 @@ run these steps:

    9. Let rangeEnd be the result of collecting a sequence of code points that are in the range U+0030 (0) to U+0039 (9), inclusive, from data given position. +

    10. If position is not past the end of data, return false. +

    11. If rangeEnd's length is 0, then return true. From 73efad3cb1b247ae6a2a3373f97f6e79d490fb5b Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 12:55:20 +0100 Subject: [PATCH 11/15] Wrapping and tweaks --- fetch.bs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fetch.bs b/fetch.bs index ab963274b..2a60ced1e 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1050,15 +1050,21 @@ run these steps:

    12. If data does not start with "bytes=", then return false. -

    13. Let position be a position variable for data, initially pointing at the 6th code point of data. +

    14. Let position be a position variable for data, initially + pointing at the 6th code point of data. -

    15. Let rangeStart be the result of collecting a sequence of code points that are in the range U+0030 (0) to U+0039 (9), inclusive, from data given position. +

    16. Let rangeStart be the result of collecting a sequence of code points that + are in the range U+0030 (0) to U+0039 (9), inclusive, from data given + position. -

    17. If the code point at position within data is not U+002D (-), then return false. +

    18. If the code point at position within data is not U+002D (-), + then return false.

    19. Advance position by 1. -

    20. Let rangeEnd be the result of collecting a sequence of code points that are in the range U+0030 (0) to U+0039 (9), inclusive, from data given position. +

    21. Let rangeEnd be the result of collecting a sequence of code points that + are in the range U+0030 (0) to U+0039 (9), inclusive, from data given + position.

    22. If position is not past the end of data, return false. @@ -1074,7 +1080,7 @@ run these steps:

    A simple range header value is a subset of allowed range header values, but -it's the most common form used by user agents when requesting media or resuming downloads. This +it is the most common form used by user agents when requesting media or resuming downloads. This format of range header value can be set using add a range header.


    From 057361d7c6a3515d8bed15a895690a2403804f0c Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 28 Sep 2021 13:03:41 +0100 Subject: [PATCH 12/15] Parsing as number change --- fetch.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fetch.bs b/fetch.bs index 2a60ced1e..4a8efda15 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1073,8 +1073,8 @@ run these steps:

    The range end can be omitted, e.g., `bytes 0-` is valid. -

  • If rangeStart, parsed as an integer, is greater than rangeEnd, parsed - as an integer, then return false. +

  • If rangeStart, interpreted as decimal number, is greater than + rangeEnd, interpreted as decimal number, then return false.

  • Return true. From fe9e16d824899cf91df4e1d11b64efeff3afe626 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Wed, 29 Sep 2021 08:50:50 +0100 Subject: [PATCH 13/15] Update fetch.bs Co-authored-by: Anne van Kesteren --- fetch.bs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fetch.bs b/fetch.bs index 4a8efda15..d43c55dbd 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1054,8 +1054,7 @@ run these steps: pointing at the 6th code point of data.

  • Let rangeStart be the result of collecting a sequence of code points that - are in the range U+0030 (0) to U+0039 (9), inclusive, from data given - position. + are ASCII digits, from data given position.

  • If the code point at position within data is not U+002D (-), then return false. From cf6719a1d86d6324a843f4be96ddd2c0def6e968 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Wed, 29 Sep 2021 08:50:59 +0100 Subject: [PATCH 14/15] Update fetch.bs Co-authored-by: Anne van Kesteren --- fetch.bs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fetch.bs b/fetch.bs index d43c55dbd..494b97a5c 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1062,8 +1062,7 @@ run these steps:

  • Advance position by 1.

  • Let rangeEnd be the result of collecting a sequence of code points that - are in the range U+0030 (0) to U+0039 (9), inclusive, from data given - position. + are ASCII digits, from data given position.

  • If position is not past the end of data, return false. From ed0a9cab11ab36a85454d67e38b3ab3c0c536742 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Wed, 29 Sep 2021 08:51:11 +0100 Subject: [PATCH 15/15] Update fetch.bs Co-authored-by: Anne van Kesteren --- fetch.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fetch.bs b/fetch.bs index 494b97a5c..8ff5cfd65 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1064,7 +1064,7 @@ run these steps:

  • Let rangeEnd be the result of collecting a sequence of code points that are ASCII digits, from data given position. -

  • If position is not past the end of data, return false. +

  • If position is not past the end of data, then return false.

  • If rangeEnd's length is 0, then return true.