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(doc): Remove unnecessary http header for iOS #1167

Merged
merged 2 commits into from
Jan 30, 2020
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
8 changes: 0 additions & 8 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ class DocBaseViewer extends BaseViewer {
const { file, location } = this.options;
const { size, watermark_info: watermarkInfo } = file;
const assetUrlCreator = createAssetUrlCreator(location);
const httpHeaders = {};
const queryParams = {};

// Do not disable create object URL in IE11 or iOS Chrome - pdf.js issues #3977 and #8081 are
Expand All @@ -669,12 +668,6 @@ class DocBaseViewer extends BaseViewer {
const rangeChunkSizeDefault = location.locale === 'en-US' ? RANGE_CHUNK_SIZE_US : RANGE_CHUNK_SIZE_NON_US;
const rangeChunkSize = this.getViewerOption('rangeChunkSize') || rangeChunkSizeDefault;

// Fix incorrectly cached range requests on older versions of iOS webkit browsers,
// see: https://bugs.webkit.org/show_bug.cgi?id=82672
if (Browser.isIOS()) {
httpHeaders['If-None-Match'] = 'webkit-no-cache';
mxiao6 marked this conversation as resolved.
Show resolved Hide resolved
}

// If range requests are disabled, request the gzip compressed version of the representation
this.encoding = disableRange ? ENCODING_TYPES.GZIP : undefined;

Expand All @@ -690,7 +683,6 @@ class DocBaseViewer extends BaseViewer {
disableFontFace,
disableRange,
disableStream,
httpHeaders,
rangeChunkSize,
url: appendQueryParams(pdfUrl, queryParams),
});
Expand Down
24 changes: 0 additions & 24 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1216,37 +1216,16 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
return docBase.initViewer(url).then(() => {
expect(stubs.getDocument).to.be.calledWith(
sinon.match({
httpHeaders: sinon.match.object,
rangeChunkSize: largeChunkSize,
}),
);
});
});

it('should set a cache-busting header if on mobile', () => {
docBase.options.location = {
locale: 'en-US',
};
sandbox.stub(Browser, 'isIOS').returns(true);

return docBase.initViewer('').then(() => {
expect(stubs.getDocument).to.be.calledWith(
sinon.match({
httpHeaders: {
'If-None-Match': 'webkit-no-cache',
},
rangeChunkSize: 1048576,
}),
);
});
});

it('should avoid preflight requests by not adding non-standard headers', done => {
docBase.options.location = {
locale: 'en-US',
};
// Excluding IOS for If-None-Match cache busting
sandbox.stub(Browser, 'isIOS').returns(false);
stubs.getDocument.callsFake(docInitParams => {
return new Promise(() => {
const { httpHeaders = {} } = docInitParams;
Expand Down Expand Up @@ -1280,7 +1259,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
return docBase.initViewer(url).then(() => {
expect(stubs.getDocument).to.be.calledWith(
sinon.match({
httpHeaders: sinon.match.object,
rangeChunkSize: defaultChunkSize,
url: `${url}?${paramsList}`,
}),
Expand Down Expand Up @@ -1665,7 +1643,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
beforeEach(() => {
stubs.addEventListener = sandbox.stub(docBase.docEl, 'addEventListener');
stubs.addListener = sandbox.stub(fullscreen, 'addListener');
stubs.isIOS = sandbox.stub(Browser, 'isIOS');
});

it('should add the correct listeners', () => {
Expand All @@ -1692,7 +1669,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
beforeEach(() => {
stubs.removeEventListener = sandbox.stub(docBase.docEl, 'removeEventListener');
stubs.removeFullscreenListener = sandbox.stub(fullscreen, 'removeListener');
stubs.isIOS = sandbox.stub(Browser, 'isIOS');
});

it('should remove the docBase element listeners if the docBase element exists', () => {
Expand Down