Skip to content

Commit

Permalink
Merge pull request #198 from aloisklink/limit-range-to-file-size
Browse files Browse the repository at this point in the history
Limit maximum HTTP Range header to fileSize
  • Loading branch information
constantinius committed Feb 4, 2021
2 parents f7c511f + 21c197a commit e9817ff
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,13 @@ class BlockedSource {
}

async requestData(requestedOffset, requestedLength) {
const response = await this.retrievalFunction(requestedOffset, requestedLength);
let actualLengthToRequest = requestedLength;
if (this.fileSize !== null && requestedOffset + requestedLength > this.fileSize) {
// some HTTP servers (e.g. Aliyun OSS) do not support Range requests
// when the Range header is longer than the actual file length
actualLengthToRequest = this.fileSize - requestedOffset;
}
const response = await this.retrievalFunction(requestedOffset, actualLengthToRequest);
if (!response.length) {
response.length = response.data.byteLength;
} else if (response.length !== response.data.byteLength) {
Expand Down

0 comments on commit e9817ff

Please sign in to comment.