Skip to content

Commit e1cfb19

Browse files
Hendrixervojtajina
authored andcommitted
fix($http): ensure default headers PUT and POST are different objects
Send PUT and POST through copy() to make sure they are not the same. Closes angular#5742 Closes angular#5747 Closes angular#5764
1 parent 2a35863 commit e1cfb19

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/ng/http.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ function $HttpProvider() {
111111
common: {
112112
'Accept': 'application/json, text/plain, */*'
113113
},
114-
post: CONTENT_TYPE_APPLICATION_JSON,
115-
put: CONTENT_TYPE_APPLICATION_JSON,
116-
patch: CONTENT_TYPE_APPLICATION_JSON
114+
post: copy(CONTENT_TYPE_APPLICATION_JSON),
115+
put: copy(CONTENT_TYPE_APPLICATION_JSON),
116+
patch: copy(CONTENT_TYPE_APPLICATION_JSON)
117117
},
118118

119119
xsrfCookieName: 'XSRF-TOKEN',
@@ -324,7 +324,7 @@ function $HttpProvider() {
324324
* to `push` or `unshift` a new transformation function into the transformation chain. You can
325325
* also decide to completely override any default transformations by assigning your
326326
* transformation functions to these properties directly without the array wrapper. These defaults
327-
* are again available on the $http factory at run-time, which may be useful if you have run-time
327+
* are again available on the $http factory at run-time, which may be useful if you have run-time
328328
* services you wish to be involved in your transformations.
329329
*
330330
* Similarly, to locally override the request/response transforms, augment the

test/ng/httpSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,12 @@ describe('$http', function() {
14391439
$http.get('/url');
14401440
$httpBackend.flush();
14411441
});
1442+
1443+
it('should have seperate opbjects for defaults PUT and POST', function() {
1444+
expect($http.defaults.headers.post).not.toBe($http.defaults.headers.put);
1445+
expect($http.defaults.headers.post).not.toBe($http.defaults.headers.patch);
1446+
expect($http.defaults.headers.put).not.toBe($http.defaults.headers.patch);
1447+
})
14421448
});
14431449
});
14441450

0 commit comments

Comments
 (0)