Skip to content

Commit

Permalink
fix: content length for byte range requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Sep 10, 2024
1 parent 5d5c3a5 commit 9248917
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/handlers/unixfs-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export async function handleUnixfsFile (request, env, ctx) {
if (range && Number(entry.size) !== contentLength) {
const contentRange = `bytes ${range[0]}-${range[1]}/${entry.size}`
headers['Content-Range'] = contentRange
headers['Content-Length'] = contentLength.toString()
}

// stream the remainder
Expand Down
3 changes: 3 additions & 0 deletions test/handlers/unixfs-file.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('UnixFS file handler', async () => {

assert.equal(res.status, 206)
assert.equal(res.headers.get('Content-Range'), `bytes ${first}-${last}/${fileData.length}`)
assert.equal(res.headers.get('Content-Length'), last - first + 1)
const data = await res.text()
assert.equal(data, 'est')
})
Expand All @@ -46,6 +47,7 @@ describe('UnixFS file handler', async () => {

assert.equal(res.status, 206)
assert.equal(res.headers.get('Content-Range'), `bytes ${first}-${fileData.length - 1}/${fileData.length}`)
assert.equal(res.headers.get('Content-Length'), fileData.length - first)
const data = await res.text()
assert.equal(data, 'est')
})
Expand All @@ -57,6 +59,7 @@ describe('UnixFS file handler', async () => {

assert.equal(res.status, 206)
assert.equal(res.headers.get('Content-Range'), `bytes ${fileData.length + suffix}-${fileData.length - 1}/${fileData.length}`)
assert.equal(res.headers.get('Content-Length'), -suffix)
const data = await res.text()
assert.equal(data, 'est')
})
Expand Down

0 comments on commit 9248917

Please sign in to comment.