[whatwg/fetch] Range header 'helper' produces incorrect header value (#1265)

Snapshot: [d20e8c9](https://fetch.spec.whatwg.org/commit-snapshots/d20e8c932a639d04fb8251eb6d647fcd54ef47fd/#concept-request-add-range-header)

The spec currently outlines the process for adding a `Range` header to a request:

> To add a range header to a request _request_, with an integer _first_, and an optional integer _last_, run these steps:​
> 
> 1. Let _rangeValue_ be \`<code>bytes </code>\`\.
> 2. Serialize and isomorphic encode first, and append the result to _rangeValue_\.
> 3. Append 0x2D \(\-\) to rangeValue\.
> 4. If _last_ is given, then serialize and isomorphic encode it, and append the result to _rangeValue_\.
> 5. Append \`<code>Range</code>\`/_rangeValue_ to _request_’s header list\.

As an example, if _first_ and _last_ had values of 3 and 5, I think this would result in a `Range` header value of `bytes 3-5` when it should be `bytes=3-5`, with 0x3D (=) as the separator.

Per RFC 7233 §2.1:<sup>[\[1\]][1]</sup>

> The "bytes" range unit is defined for expressing subranges of the data's octet sequence.
>
>     bytes-unit       = "bytes"
>
> […]
>
>     byte-ranges-specifier = bytes-unit "=" byte-range-set
>     byte-range-set  = 1#( byte-range-spec / suffix-byte-range-spec )

> Examples of byte-ranges-specifier values:
>
> - The first 500 bytes (byte offsets 0-499, inclusive): `bytes=0-499`
> - The second 500 bytes (byte offsets 500-999, inclusive): `bytes=500-999`

It should be a simple enough fix, unless I'm missing something:

```diff
- <li><p>Let <var>rangeValue</var> be `<code>bytes </code>`.
+ <li><p>Let <var>rangeValue</var> be `<code>bytes=</code>`.
```

I'm willing to open a PR for this, if that would be useful.

  [1]:https://httpwg.org/specs/rfc7233.html#byte.ranges


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1265

Received on Sunday, 4 July 2021 20:11:01 UTC