Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: range end is zero-indexed #3826

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/handler/retry-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class RetryHandler {
return false
}

const { start, size, end = size } = contentRange
const { start, size, end = size - 1 } = contentRange

assert(this.start === start, 'content-range mismatch')
assert(this.end == null || this.end === end, 'content-range mismatch')
Expand All @@ -252,7 +252,7 @@ class RetryHandler {
)
}

const { start, size, end = size } = range
const { start, size, end = size - 1 } = range
assert(
start != null && Number.isFinite(start),
'content-range mismatch'
Expand All @@ -266,7 +266,7 @@ class RetryHandler {
// We make our best to checkpoint the body for further range headers
if (this.end == null) {
const contentLength = headers['content-length']
this.end = contentLength != null ? Number(contentLength) : null
this.end = contentLength != null ? Number(contentLength) - 1 : null
}

assert(Number.isFinite(this.start))
Expand Down
5 changes: 3 additions & 2 deletions test/interceptors/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,15 @@ test('Should handle 206 partial content', async t => {
const server = createServer((req, res) => {
if (x === 0) {
t.ok(true, 'pass')
res.setHeader('content-length', '6')
res.setHeader('etag', 'asd')
res.write('abc')
setTimeout(() => {
res.destroy()
}, 1e2)
} else if (x === 1) {
t.deepStrictEqual(req.headers.range, 'bytes=3-')
res.setHeader('content-range', 'bytes 3-6/6')
t.deepStrictEqual(req.headers.range, 'bytes=3-5')
res.setHeader('content-range', 'bytes 3-5/6')
res.setHeader('etag', 'asd')
res.statusCode = 206
res.end('def')
Expand Down
Loading