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: Older versions of webkit iOS incorrectly cache range requests #118

Merged
merged 2 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ export function replacePlaceholders(string, placeholderValues) {
/* eslint-enable no-plusplus */
});
}

/**
* Check to see if a file requires a Box3D viewer to be viewed
*
Expand Down
21 changes: 15 additions & 6 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ class DocBaseViewer extends BaseViewer {
* @return {Promise} Promise to initialize Viewer
*/
initViewer(pdfUrl) {
this.bindDOMListeners();

// Initialize PDF.js in container
this.pdfViewer = new PDFJS.PDFViewer({
container: this.docEl,
Expand All @@ -531,15 +533,22 @@ class DocBaseViewer extends BaseViewer {
RANGE_REQUEST_CHUNK_SIZE_NON_US;
}

this.bindDOMListeners();

// Load PDF from representation URL
this.pdfLoadingTask = PDFJS.getDocument({
const docInitParams = {
url: pdfUrl,
rangeChunkSize
});
};

// Fix incorrectly cached range requests on older versions of iOS webkit browsers,
// see: https://bugs.webkit.org/show_bug.cgi?id=82672
if (this.isMobile && Browser.isIOS()) {
docInitParams.httpHeaders = {
'If-None-Match': 'webkit-no-cache'
};
}

// Set document for PDF.js
// Load PDF from representation URL and set as document for pdf.js. Cache
// the loading task so we can cancel if needed
this.pdfLoadingTask = PDFJS.getDocument(docInitParams);
return this.pdfLoadingTask.then((doc) => {
this.pdfViewer.setDocument(doc);

Expand Down
19 changes: 19 additions & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,25 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
});
});

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

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

it('should resolve the loading task and set the document/viewer', () => {
const doc = {
url: 'url'
Expand Down