Skip to content

Commit

Permalink
feat(Server): should send Content-Range if not full body
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Jul 29, 2022
1 parent ad7357e commit 7d5a5f5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/server/js/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,15 @@ class Response extends Writable {
return
}
this._setupStreamMeta(stream)
const ranges = parseRange(this._totalSize, this.connection.headers.range || '', { combine: true })
const ranges = this._status === 200 &&
parseRange(this._totalSize, this.connection.headers.range || '', { combine: true })
// TODO: Support for multipart/byteranges
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
this.status(206)
.setHeader('Content-Range', `bytes ${start}-${end}/${this._totalSize}`)
return stream.pipe(rangeStream(ranges)).pipe(this)
}
}
Expand Down

0 comments on commit 7d5a5f5

Please sign in to comment.