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

Chore: remove x-box-accept-encoding header to prevent OPTIONS call #841

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
4 changes: 0 additions & 4 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ export const X_REP_HINT_IMAGE = '[jpg?dimensions=2048x2048,png?dimensions=2048x2
export const X_REP_HINT_VIDEO_DASH = '[dash,mp4][filmstrip]';
export const X_REP_HINT_VIDEO_MP4 = '[mp4]';

// X-Box-Accept-Encoding Header for requesting non-gzipped representation
export const X_BOX_ACCEPT_ENCODING_HEADER = 'x-box-accept-encoding';
export const X_BOX_ACCEPT_ENCODING_IDENTITY = 'identity';

export const PDFJS_CSS_UNITS = 96.0 / 72.0; // Should match CSS_UNITS in pdf_viewer.js
export const PDFJS_MAX_AUTO_SCALE = 1.25; // Should match MAX_AUTO_SCALE in pdf_viewer.js
export const PDFJS_WIDTH_PADDING_PX = 40; // Should match SCROLLBAR_PADDING in pdf_viewer.js
Expand Down
10 changes: 1 addition & 9 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {
DOC_STATIC_ASSETS_VERSION,
PERMISSION_DOWNLOAD,
PRELOAD_REP_NAME,
STATUS_SUCCESS,
X_BOX_ACCEPT_ENCODING_HEADER,
X_BOX_ACCEPT_ENCODING_IDENTITY
STATUS_SUCCESS
} from '../../constants';
import { checkPermission, getRepresentation } from '../../file';
import { get, createAssetUrlCreator, getMidpoint, getDistance, getClosestPageToPinch } from '../../util';
Expand Down Expand Up @@ -585,12 +583,6 @@ class DocBaseViewer extends BaseViewer {
};
}

// If range requests are enabled, request the non-gzip compressed version of the representation
if (!PDFJS.disableRange) {
docInitParams.httpHeaders = docInitParams.httpHeaders || {};
docInitParams.httpHeaders[X_BOX_ACCEPT_ENCODING_HEADER] = X_BOX_ACCEPT_ENCODING_IDENTITY;
}

// Start timing document load
this.startLoadTimer();

Expand Down
28 changes: 1 addition & 27 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import {
PERMISSION_DOWNLOAD,
STATUS_ERROR,
STATUS_PENDING,
STATUS_SUCCESS,
X_BOX_ACCEPT_ENCODING_HEADER,
X_BOX_ACCEPT_ENCODING_IDENTITY
STATUS_SUCCESS
} from '../../../constants';

import { ICON_PRINT_CHECKMARK } from '../../../icons/icons';
Expand Down Expand Up @@ -922,30 +920,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
});
});

it('should set a x-box-accept-encoding header when range requests are enabled', () => {
docBase.options.location = {
locale: 'en-GB'
};
const isDisbled = PDFJS.disableRange;
sandbox.stub(Browser, 'isIOS').returns(false);
sandbox.stub(PDFJS, 'getDocument').returns(Promise.resolve({}));

PDFJS.disableRange = false;

return docBase.initViewer('').then(() => {
expect(PDFJS.getDocument).to.be.calledWith({
url: '',
rangeChunkSize: 524288,
httpHeaders: {
[X_BOX_ACCEPT_ENCODING_HEADER]: X_BOX_ACCEPT_ENCODING_IDENTITY
}
});

// Reset to original value
PDFJS.disableRange = isDisbled;
});
});

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