Skip to content

Commit

Permalink
fix(viewer): Re-enable support for range requests for most users (#1072)
Browse files Browse the repository at this point in the history
* fix(viewer): change back disableRange logic

* fix(viewer): change tests

* fix(viewer): fix test
  • Loading branch information
Mingze authored and mergify[bot] committed Sep 16, 2019
1 parent 6f122bd commit 83424d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ class DocBaseViewer extends BaseViewer {
// Disable range requests for files smaller than MINIMUM_RANGE_REQUEST_FILE_SIZE (25MB) for
// previews outside of the US since the additional latency overhead per range request can be
// more than the additional time for a continuous request.
const isRangeSupported = location.locale !== 'en-US' && size > RANGE_REQUEST_MINIMUM_SIZE;
const isRangeSupported = location.locale === 'en-US' || size >= RANGE_REQUEST_MINIMUM_SIZE;
const isWatermarked = watermarkInfo && watermarkInfo.is_watermarked;
const disableRange = isWatermarked || !isRangeSupported;

Expand Down
12 changes: 8 additions & 4 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,11 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
});
});

it('should disable range requests if the locale is en-US', () => {
it('should not disable range requests if the locale is en-US', () => {
docBase.options.location.locale = 'en-US';

return docBase.initViewer('').then(() => {
expect(stubs.getDocument).to.be.calledWith(sinon.match({ disableRange: true }));
expect(stubs.getDocument).to.be.calledWith(sinon.match({ disableRange: false }));
});
});

Expand Down Expand Up @@ -1271,12 +1271,16 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
});

it('should append encoding query parameter for gzip content when range requests are disabled', () => {
const defaultChunkSize = 1048576; // Taken from RANGE_REQUEST_CHUNK_SIZE_US
const defaultChunkSize = 524288; // Taken from RANGE_CHUNK_SIZE_NON_US
const url = 'www.myTestPDF.com/123456';
const paramsList = `${QUERY_PARAM_ENCODING}=${ENCODING_TYPES.GZIP}`;

docBase.options.location = {
locale: 'en-US', // Disables range requests
locale: 'ja-JP', // Disables range requests
};

docBase.options.file = {
size: 1048576, // 1MB < RANGE_REQUEST_MINIMUM_SIZE (25MB)
};

return docBase.initViewer(url).then(() => {
Expand Down

0 comments on commit 83424d0

Please sign in to comment.