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

Commit

Permalink
feat($http): make the transform defaults to an array
Browse files Browse the repository at this point in the history
$httpProvider.defaults.transformRequest and $httpProvider.defaults.transformResponse
are now arrays containing single function. This makes it easy to add an
extra transform fn.

adding an extra fn before had to be done in this cluncky way:

$httpProvider.defaults.transformResponse =
[$httpProvider.defaults.transformResponse, myTransformFn];

after this change, it's simply:

$httpProvider.defaults.transformResponse.push(myTransformFn);
  • Loading branch information
IgorMinar committed Mar 28, 2012
1 parent 13a95ae commit a8a750a
Showing 1 changed file with 4 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 @@ -90,20 +90,20 @@ function $HttpProvider() {

var $config = this.defaults = {
// transform incoming response data
transformResponse: function(data) {
transformResponse: [function(data) {
if (isString(data)) {
// strip json vulnerability protection prefix
data = data.replace(PROTECTION_PREFIX, '');
if (JSON_START.test(data) && JSON_END.test(data))
data = fromJson(data, true);
}
return data;
},
}],

// transform outgoing request data
transformRequest: function(d) {
transformRequest: [function(d) {
return isObject(d) && !isFile(d) ? toJson(d) : d;
},
}],

// default headers
headers: {
Expand Down

0 comments on commit a8a750a

Please sign in to comment.