Skip to content

Commit

Permalink
fix(Server): correct Content-Range implement
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Aug 3, 2022
1 parent 841c623 commit 7e37844
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/server/js/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ class Response extends Writable {
if (Array.isArray(ranges) && ranges.length === 1 && ranges.type === 'bytes') {
const [{ start, end }] = ranges
if (this._totalSize && end <= this._totalSize) {
this._totalSize = end - start
this.status(206)
.setHeader('Content-Range', `bytes ${start}-${end}/${this._totalSize}`)
this._totalSize = end - start
return stream.pipe(rangeStream(ranges)).pipe(this)
}
}
Expand Down
5 changes: 4 additions & 1 deletion test/cases/http-pipe-file-stream-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ module.exports = async function ({ HTTP_PORT }) {
throw new Error('Unknown Content-Type')
}
if (Number(res.headers['content-length']) !== 4) {
throw new Error(`Invalid Content-Length ${res.headers['content-length']}`)
throw new Error(`Invalid Content-Length: ${res.headers['content-length']}`)
}
if (!['bytes 0-4/10', 'bytes 0-4/11'].includes(res.headers['content-range'])) {
throw new Error(`Invalid Content-Range: ${res.headers['content-range']}`)
}
if (res.data !== 'TEST') {
throw new Error('Response data mismatch')
Expand Down

0 comments on commit 7e37844

Please sign in to comment.