Skip to content

fix(fetch): use headersList for Range check on opaque 206 response#5043

Open
deepview-autofix wants to merge 1 commit intonodejs:mainfrom
deepview-autofix:deepview/909d810428
Open

fix(fetch): use headersList for Range check on opaque 206 response#5043
deepview-autofix wants to merge 1 commit intonodejs:mainfrom
deepview-autofix:deepview/909d810428

Conversation

@deepview-autofix
Copy link
Copy Markdown
Contributor

The internal request state has a headersList property, not headers. Accessing request.headers.contains('range', true) would throw a TypeError when processing an opaque response with status 206 and the range-requested flag set.

The internal request state has a `headersList` property, not `headers`.
Accessing `request.headers.contains('range', true)` would throw a
TypeError when processing an opaque response with status 206 and the
range-requested flag set.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: DeepView Autofix <276251120+deepview-autofix@users.noreply.github.com>
Co-Authored-By: Nikita Skovoroda <chalkerx@gmail.com>
Signed-off-by: Nikita Skovoroda <chalkerx@gmail.com>
Copy link
Copy Markdown
Member

@KhafraDev KhafraDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks correct, could you add a test?

@ChALkeR
Copy link
Copy Markdown
Member

ChALkeR commented Apr 16, 2026

@KhafraDev for this one too, agent claimed the code is actually dead, and opted out from making a test:

Tests pass. The fix is a clear typo correction — the buggy branch is essentially dead code in undici (rangeRequested is only ever set when request has Range), so adding a regression test would be artificial. Per instructions, no test is better than a useless test.

That might be a mistake though

If anyone can write a test for this it would be nice

@KhafraDev
Copy link
Copy Markdown
Member

await t.test('a range fetch request returns the inclusive byte range', async () => {
const res = await fetch(objectURL, {
headers: {
Range: 'bytes=1-3'
}
})
t.assert.strictEqual(res.status, 206)
t.assert.strictEqual(await res.text(), blobContents.slice(1, 4))
t.assert.strictEqual(res.headers.get('Content-Length'), '3')
t.assert.strictEqual(res.headers.get('Content-Range'), `bytes 1-3/${blob.size}`)
})

A test similar to this one perhaps?

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.03%. Comparing base (bc0a19c) to head (f489eee).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
lib/web/fetch/index.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5043      +/-   ##
==========================================
- Coverage   93.03%   93.03%   -0.01%     
==========================================
  Files         110      110              
  Lines       35793    35793              
==========================================
- Hits        33301    33300       -1     
- Misses       2492     2493       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants