Skip to content

Conversation

@severo
Copy link
Contributor

@severo severo commented Oct 9, 2025

otherwise, browsers cannot access it, because it's not among the CORS-safelisted response headers:
https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header

What I'm changing

Responses to range requests already include the Content-Range header.

But browsers cannot read its value, because it's not among the CORS-safelisted response headers.

With this PR, the responses also include the header Access-Control-Expose-Headers: Content-Range, to allow browsers to access the Content-Range header.

How I did it

I add the header, when the request was a range request.

How to test it

Go to https://observablehq.com/@severo/bug-in-source-coop-content-range-is-not-accessible

Or test the following in a browser (not in Node.js)

function test(url) {
  return fetch(url, { headers: { range: "bytes=0-100" } }).then((r) => 
    r.headers.get("Content-Range") === "bytes 0-100/70940" ? "Success": "Error"
  );
}

This function should return "Success" for any data file hosted by the proxy.

For example:

test("https://data.source.coop/severo/csv-papaparse-test-files/verylong-sample.csv") // "Success"

// by comparison:
test("https://huggingface.co/datasets/severo/csv-papaparse-test-files/resolve/main/verylong-sample.csv") // "Success", since HF allows accessing this header
test("https://s3.us-west-2.amazonaws.com/us-west-2.opendata.source.coop/severo/csv-papaparse-test-files/verylong-sample.csv") // "Error", since S3 does not allow accessing this header

PR Checklist

  • This PR has no breaking changes.
  • I have updated or added new tests to cover the changes in this PR.

I'm not a Rust developer, and the main.rs file has no tests, so: I don't feel comfortable creating tests in that file from scratch.

Related Issues

otherwise, browsers cannot access it, because it's not among the
CORS-safelisted response headers:
https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header
@severo severo changed the title expose content-range header fix: expose content-range header Oct 9, 2025
@severo severo requested review from alukach and jedsundwall October 9, 2025 20:58
@severo severo merged commit f3fbc3d into main Oct 9, 2025
4 of 6 checks passed
@severo severo deleted the expose-content-range branch October 9, 2025 21:49
severo pushed a commit that referenced this pull request Oct 10, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.0.2](v1.0.1...v1.0.2)
(2025-10-09)


### Bug Fixes

* expose content-range header
([#93](#93))
([f3fbc3d](f3fbc3d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: source-coop-release[bot] <187876225+source-coop-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants