|
|
@@ -92,16 +92,17 @@ function headersGetter(headers) { |
|
|
* This function is used for both request and response transforming |
|
|
* |
|
|
* @param {*} data Data to transform. |
|
|
* @param {function(string=)} headers Http headers getter fn. |
|
|
* @param {function(string=)} headers HTTP headers getter fn. |
|
|
* @param {number} status HTTP status code of the response. |
|
|
* @param {(Function|Array.<Function>)} fns Function or an array of functions. |
|
|
* @returns {*} Transformed data. |
|
|
*/ |
|
|
function transformData(data, headers, fns) { |
|
|
function transformData(data, headers, status, fns) { |
|
|
if (isFunction(fns)) |
|
|
return fns(data, headers); |
|
|
return fns(data, headers, status); |
|
|
|
|
|
forEach(fns, function(fn) { |
|
|
data = fn(data, headers); |
|
|
data = fn(data, headers, status); |
|
|
}); |
|
|
|
|
|
return data; |
|
|
@@ -380,7 +381,7 @@ function $HttpProvider() { |
|
|
* |
|
|
* Both requests and responses can be transformed using transformation functions: `transformRequest` |
|
|
* and `transformResponse`. These properties can be a single function that returns |
|
|
* the transformed value (`{function(data, headersGetter)`) or an array of such transformation functions, |
|
|
* the transformed value (`{function(data, headersGetter, status)`) or an array of such transformation functions, |
|
|
* which allows you to `push` or `unshift` a new transformation function into the transformation chain. |
|
|
* |
|
|
* ### Default Transformations |
|
|
@@ -624,9 +625,9 @@ function $HttpProvider() { |
|
|
* See {@link ng.$http#overriding-the-default-transformations-per-request |
|
|
* Overriding the Default Transformations} |
|
|
* - **transformResponse** – |
|
|
* `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` – |
|
|
* `{function(data, headersGetter, status)|Array.<function(data, headersGetter, status)>}` – |
|
|
* transform function or an array of such functions. The transform function takes the http |
|
|
* response body and headers and returns its transformed (typically deserialized) version. |
|
|
* response body, headers and status and returns its transformed (typically deserialized) version. |
|
|
* See {@link ng.$http#overriding-the-default-transformations-per-request |
|
|
* Overriding the Default Transformations} |
|
|
* - **cache** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the |
|
|
@@ -765,7 +766,7 @@ function $HttpProvider() { |
|
|
|
|
|
var serverRequest = function(config) { |
|
|
var headers = config.headers; |
|
|
var reqData = transformData(config.data, headersGetter(headers), config.transformRequest); |
|
|
var reqData = transformData(config.data, headersGetter(headers), undefined, config.transformRequest); |
|
|
|
|
|
// strip content-type if data is undefined |
|
|
if (isUndefined(reqData)) { |
|
|
@@ -826,7 +827,7 @@ function $HttpProvider() { |
|
|
if (!response.data) { |
|
|
resp.data = response.data; |
|
|
} else { |
|
|
resp.data = transformData(response.data, response.headers, config.transformResponse); |
|
|
resp.data = transformData(response.data, response.headers, response.status, config.transformResponse); |
|
|
} |
|
|
return (isSuccess(response.status)) |
|
|
? resp |
|
|
|