Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(viewer): Re-enable support for range requests for most users #1072

Merged
merged 3 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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