Skip to content

Commit 8942ee6

Browse files
mikosczigorT
authored andcommitted
[BUGFIX adapter]: Fix problem with headers precedence #6588 (#6650)
1 parent 14c84f0 commit 8942ee6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/-ember-data/tests/unit/adapters/rest-adapter/ajax-options-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,33 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function(h
194194
});
195195
});
196196

197+
test('ajaxOptions() headers take precedence over adapter headers', function(assert) {
198+
let store = this.owner.lookup('service:store');
199+
let adapter = store.adapterFor('application');
200+
201+
adapter.headers = {
202+
'Content-Type': 'application/x-www-form-urlencoded',
203+
};
204+
205+
let url = 'example.com';
206+
let type = 'POST';
207+
let ajaxOptions = adapter.ajaxOptions(url, type, {
208+
headers: {
209+
'Content-Type': 'application/json',
210+
},
211+
});
212+
213+
assert.deepEqual(ajaxOptions, {
214+
credentials: 'same-origin',
215+
type: 'POST',
216+
method: 'POST',
217+
headers: {
218+
'Content-Type': 'application/json',
219+
},
220+
url: 'example.com',
221+
});
222+
});
223+
197224
test('_fetchRequest() returns a promise', function(assert) {
198225
let store = this.owner.lookup('service:store');
199226
let adapter = store.adapterFor('application');

packages/adapter/addon/rest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, {
10861086

10871087
let headers = get(this, 'headers');
10881088
if (headers !== undefined) {
1089-
options.headers = assign({}, options.headers, headers);
1089+
options.headers = assign({}, headers, options.headers);
10901090
} else if (!options.headers) {
10911091
options.headers = {};
10921092
}

0 commit comments

Comments
 (0)