Skip to content

honor entity-tag If-Range in FileResponse range requests - #13480

Draft
arshsmith1 wants to merge 2 commits into
aio-libs:masterfrom
arshsmith1:fileresponse-ifrange-etag
Draft

honor entity-tag If-Range in FileResponse range requests#13480
arshsmith1 wants to merge 2 commits into
aio-libs:masterfrom
arshsmith1:fileresponse-ifrange-etag

Conversation

@arshsmith1

Copy link
Copy Markdown
Contributor

What do these changes do?

FileResponse only looked at the HTTP-date form of If-Range. request.if_range runs the value through parse_http_date and returns None for anything that is not a date, so an If-Range carrying an entity-tag was treated as absent and the Range was honored unconditionally. A client resuming a download with If-Range: "<etag>" after the file had changed therefore received a 206 partial that it stitched onto the stale bytes it already held, producing a corrupt file. :rfc:9110#section-13.1.5 wants the Range honored only when the validator still matches, otherwise the full 200. The strong entity-tag comparison now happens inside _prepare_open_file, next to where the date form was already handled, so a stale (or weak) validator falls back to a full 200.

Are there changes in behavior for the user?

Only for the entity-tag If-Range case. Requests with no If-Range, and the date form, behave exactly as before; a matching strong ETag still serves the 206.

Is it a substantial burden for the maintainers to support this?

No. It reads the raw If-Range header where the date form was already parsed and adds one strong comparison, with two regression tests beside the existing If-Range date tests.

Related issue number

None.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes — N/A, no public API change
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
  • Add a new news fragment into the CHANGES/ folder

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Aug 18, 2026
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.00%. Comparing base (79b5f5f) to head (7bdf1d6).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #13480      +/-   ##
==========================================
- Coverage   99.00%   99.00%   -0.01%     
==========================================
  Files         132      132              
  Lines       49626    49655      +29     
  Branches     2575     2577       +2     
==========================================
+ Hits        49132    49160      +28     
- Misses        370      371       +1     
  Partials      124      124              
Flag Coverage Δ
Autobahn 22.03% <9.37%> (-0.01%) ⬇️
CI-GHA 98.91% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.68% <100.00%> (+<0.01%) ⬆️
OS-Windows 97.01% <100.00%> (+<0.01%) ⬆️
OS-macOS 97.93% <100.00%> (-0.01%) ⬇️
Py-3.10 98.13% <100.00%> (-0.01%) ⬇️
Py-3.11 98.37% <100.00%> (-0.01%) ⬇️
Py-3.12 98.45% <100.00%> (-0.01%) ⬇️
Py-3.13 98.45% <100.00%> (+<0.01%) ⬆️
Py-3.14 98.46% <100.00%> (-0.01%) ⬇️
Py-3.14t 97.55% <100.00%> (-0.01%) ⬇️
Py-pypy-3.11 97.40% <100.00%> (-0.01%) ⬇️
VM-macos 97.93% <100.00%> (-0.01%) ⬇️
VM-ubuntu 98.68% <100.00%> (+<0.01%) ⬆️
VM-windows 97.01% <100.00%> (+<0.01%) ⬆️
cython-coverage 82.23% <50.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed-hq

codspeed-hq Bot commented Aug 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 84 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing arshsmith1:fileresponse-ifrange-etag (7bdf1d6) with master (79b5f5f)

Open in CodSpeed

Footnotes

  1. 83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant