Skip to content

Commit

Permalink
[BUGFIX adapter]: Fix problem with headers precedence #6588 (#6650)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoscz authored and igorT committed Nov 5, 2019
1 parent 3a7d468 commit 972270b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,33 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function(h
});
});

test('ajaxOptions() headers take precedence over adapter headers', function(assert) {
let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');

adapter.headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};

let url = 'example.com';
let type = 'POST';
let ajaxOptions = adapter.ajaxOptions(url, type, {
headers: {
'Content-Type': 'application/json',
},
});

assert.deepEqual(ajaxOptions, {
credentials: 'same-origin',
type: 'POST',
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
url: 'example.com',
});
});

test('_fetchRequest() returns a promise', function(assert) {
let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/addon/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, {

let headers = get(this, 'headers');
if (headers !== undefined) {
options.headers = assign({}, options.headers, headers);
options.headers = assign({}, headers, options.headers);
} else if (!options.headers) {
options.headers = {};
}
Expand Down

0 comments on commit 972270b

Please sign in to comment.