Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($http): ensure default headers PUT and POST are different objects
Browse files Browse the repository at this point in the history
Send PUT and POST through copy() to make sure they are not the same.

Closes #5742
Closes #5747
Closes #5764
  • Loading branch information
Hendrixer authored and vojtajina committed Jan 14, 2014
1 parent 2a35863 commit e1cfb19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ function $HttpProvider() {
common: {
'Accept': 'application/json, text/plain, */*'
},
post: CONTENT_TYPE_APPLICATION_JSON,
put: CONTENT_TYPE_APPLICATION_JSON,
patch: CONTENT_TYPE_APPLICATION_JSON
post: copy(CONTENT_TYPE_APPLICATION_JSON),
put: copy(CONTENT_TYPE_APPLICATION_JSON),
patch: copy(CONTENT_TYPE_APPLICATION_JSON)
},

xsrfCookieName: 'XSRF-TOKEN',
Expand Down Expand Up @@ -324,7 +324,7 @@ function $HttpProvider() {
* to `push` or `unshift` a new transformation function into the transformation chain. You can
* also decide to completely override any default transformations by assigning your
* transformation functions to these properties directly without the array wrapper. These defaults
* are again available on the $http factory at run-time, which may be useful if you have run-time
* are again available on the $http factory at run-time, which may be useful if you have run-time
* services you wish to be involved in your transformations.
*
* Similarly, to locally override the request/response transforms, augment the
Expand Down
6 changes: 6 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,12 @@ describe('$http', function() {
$http.get('/url');
$httpBackend.flush();
});

it('should have seperate opbjects for defaults PUT and POST', function() {
expect($http.defaults.headers.post).not.toBe($http.defaults.headers.put);
expect($http.defaults.headers.post).not.toBe($http.defaults.headers.patch);
expect($http.defaults.headers.put).not.toBe($http.defaults.headers.patch);
})
});
});

Expand Down

2 comments on commit e1cfb19

@caitp
Copy link
Contributor

@caitp caitp commented on e1cfb19 Jan 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turns out to have been a breaking change, it would have been really good to catch that. (#5997)

Could we edit the changelog to make a note of this?

@SimplGy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A common case for a OAuth/JWT SPA is to apply Authorization Accepts: LKDJ2398LKJDL223423 or similar to all GET/PUT/POST/PATCH requests. Any way to make this still possible with a single config option? Could keep them as separate objects but move config using angular.extend like:

angular.extend($http.defaults.headers.post, $http.defaults.headers.all)

Please sign in to comment.