Skip to content
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
1 change: 1 addition & 0 deletions src/CoreManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ const config: Config & { [key: string]: mixed } = {
!!process.versions.node &&
!process.versions.electron),
REQUEST_ATTEMPT_LIMIT: 5,
REQUEST_HEADERS: {},
SERVER_URL: 'https://api.parse.com/1',
SERVER_AUTH_TYPE: null,
SERVER_AUTH_TOKEN: null,
Expand Down
7 changes: 5 additions & 2 deletions src/RESTController.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (typeof XDomainRequest !== 'undefined' &&
useXDomainRequest = true;
}

function ajaxIE9(method: string, url: string, data: any, options?: FullOptions) {
function ajaxIE9(method: string, url: string, data: any, headers?: any, options?: FullOptions) {
return new Promise((resolve, reject) => {
const xdr = new XDomainRequest();
if (options && typeof options.requestTask === 'function') {
Expand Down Expand Up @@ -163,7 +163,10 @@ const RESTController = {
if (CoreManager.get('SERVER_AUTH_TYPE') && CoreManager.get('SERVER_AUTH_TOKEN')) {
headers['Authorization'] = CoreManager.get('SERVER_AUTH_TYPE') + ' ' + CoreManager.get('SERVER_AUTH_TOKEN');
}

const customHeaders = CoreManager.get('REQUEST_HEADERS');
for (const key in customHeaders) {
headers[key] = customHeaders[key];
}
if(options && typeof options.progress === 'function') {
if (xhr.upload) {
xhr.upload.addEventListener('progress', (oEvent) => {
Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/RESTController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,21 @@ describe('RESTController', () => {
done();
});
});

it('opens a XHR with the custom headers', () => {
CoreManager.set('REQUEST_HEADERS', { 'Cache-Control' : 'max-age=3600' });
const xhr = {
setRequestHeader: jest.fn(),
open: jest.fn(),
send: jest.fn()
};
RESTController._setXHR(function() { return xhr; });
RESTController.ajax('GET', 'users/me', {}, { 'X-Parse-Session-Token': '123' });
expect(xhr.setRequestHeader.mock.calls[3]).toEqual(
[ 'Cache-Control', 'max-age=3600' ]
);
expect(xhr.open.mock.calls[0]).toEqual([ 'GET', 'users/me', true ]);
expect(xhr.send.mock.calls[0][0]).toEqual({});
CoreManager.set('REQUEST_HEADERS', {});
});
});