Merge pull request #10133 from kevinleedrum/fix-content-length
Set returnValues.suggestedLength to Content-Length if integer
This commit is contained in:
commit
f45e46d7ad
@ -27,6 +27,20 @@ function validateRangeRequestCapabilities({ getResponseHeader, isHttp,
|
||||
allowRangeRequests: false,
|
||||
suggestedLength: undefined,
|
||||
};
|
||||
|
||||
let length = parseInt(getResponseHeader('Content-Length'), 10);
|
||||
if (!Number.isInteger(length)) {
|
||||
return returnValues;
|
||||
}
|
||||
|
||||
returnValues.suggestedLength = length;
|
||||
|
||||
if (length <= 2 * rangeChunkSize) {
|
||||
// The file size is smaller than the size of two chunks, so it does not
|
||||
// make any sense to abort the request and retry with a range request.
|
||||
return returnValues;
|
||||
}
|
||||
|
||||
if (disableRange || !isHttp) {
|
||||
return returnValues;
|
||||
}
|
||||
@ -39,18 +53,6 @@ function validateRangeRequestCapabilities({ getResponseHeader, isHttp,
|
||||
return returnValues;
|
||||
}
|
||||
|
||||
let length = parseInt(getResponseHeader('Content-Length'), 10);
|
||||
if (!Number.isInteger(length)) {
|
||||
return returnValues;
|
||||
}
|
||||
|
||||
returnValues.suggestedLength = length;
|
||||
if (length <= 2 * rangeChunkSize) {
|
||||
// The file size is smaller than the size of two chunks, so it does not
|
||||
// make any sense to abort the request and retry with a range request.
|
||||
return returnValues;
|
||||
}
|
||||
|
||||
returnValues.allowRangeRequests = true;
|
||||
return returnValues;
|
||||
}
|
||||
|
@ -23,11 +23,6 @@ import {
|
||||
|
||||
describe('network_utils', function() {
|
||||
describe('validateRangeRequestCapabilities', function() {
|
||||
const defaultValues = {
|
||||
allowRangeRequests: false,
|
||||
suggestedLength: undefined,
|
||||
};
|
||||
|
||||
it('rejects range chunk sizes that are not larger than zero', function() {
|
||||
expect(function() {
|
||||
validateRangeRequestCapabilities({ rangeChunkSize: 0, });
|
||||
@ -38,14 +33,30 @@ describe('network_utils', function() {
|
||||
expect(validateRangeRequestCapabilities({
|
||||
disableRange: true,
|
||||
isHttp: true,
|
||||
getResponseHeader: (headerName) => {
|
||||
if (headerName === 'Content-Length') {
|
||||
return 8;
|
||||
}
|
||||
},
|
||||
rangeChunkSize: 64,
|
||||
})).toEqual(defaultValues);
|
||||
})).toEqual({
|
||||
allowRangeRequests: false,
|
||||
suggestedLength: 8,
|
||||
});
|
||||
|
||||
expect(validateRangeRequestCapabilities({
|
||||
disableRange: false,
|
||||
isHttp: false,
|
||||
getResponseHeader: (headerName) => {
|
||||
if (headerName === 'Content-Length') {
|
||||
return 8;
|
||||
}
|
||||
},
|
||||
rangeChunkSize: 64,
|
||||
})).toEqual(defaultValues);
|
||||
})).toEqual({
|
||||
allowRangeRequests: false,
|
||||
suggestedLength: 8,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects invalid Accept-Ranges header values', function() {
|
||||
@ -55,10 +66,15 @@ describe('network_utils', function() {
|
||||
getResponseHeader: (headerName) => {
|
||||
if (headerName === 'Accept-Ranges') {
|
||||
return 'none';
|
||||
} else if (headerName === 'Content-Length') {
|
||||
return 8;
|
||||
}
|
||||
},
|
||||
rangeChunkSize: 64,
|
||||
})).toEqual(defaultValues);
|
||||
})).toEqual({
|
||||
allowRangeRequests: false,
|
||||
suggestedLength: 8,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects invalid Content-Encoding header values', function() {
|
||||
@ -70,10 +86,15 @@ describe('network_utils', function() {
|
||||
return 'bytes';
|
||||
} else if (headerName === 'Content-Encoding') {
|
||||
return 'gzip';
|
||||
} else if (headerName === 'Content-Length') {
|
||||
return 8;
|
||||
}
|
||||
},
|
||||
rangeChunkSize: 64,
|
||||
})).toEqual(defaultValues);
|
||||
})).toEqual({
|
||||
allowRangeRequests: false,
|
||||
suggestedLength: 8,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects invalid Content-Length header values', function() {
|
||||
@ -90,7 +111,10 @@ describe('network_utils', function() {
|
||||
}
|
||||
},
|
||||
rangeChunkSize: 64,
|
||||
})).toEqual(defaultValues);
|
||||
})).toEqual({
|
||||
allowRangeRequests: false,
|
||||
suggestedLength: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects file sizes that are too small for range requests', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user