aboutsummaryrefslogtreecommitdiffstats
path: root/src/service/xhr.js
diff options
context:
space:
mode:
authorKarl Seamon2011-07-29 18:32:30 -0400
committerIgor Minar2011-08-19 01:20:45 -0700
commit4ec1d8ee86e3138fb91543ca0dca28463895c090 (patch)
tree9f7fff13f177317ff15f8804789a44576a151908 /src/service/xhr.js
parentc37bfde9eb31556ee1eb146795b0c1f1504a4a26 (diff)
downloadangular.js-4ec1d8ee86e3138fb91543ca0dca28463895c090.tar.bz2
feat($xhr,$resource): expose response headers in callbacks
all $xhr*, $resource and related mocks now have access to headers from their callbacks
Diffstat (limited to 'src/service/xhr.js')
-rw-r--r--src/service/xhr.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/service/xhr.js b/src/service/xhr.js
index 70fcd067..6bff6f04 100644
--- a/src/service/xhr.js
+++ b/src/service/xhr.js
@@ -96,7 +96,7 @@
* angular generated callback function.
* @param {(string|Object)=} post Request content as either a string or an object to be stringified
* as JSON before sent to the server.
- * @param {function(number, (string|Object))} success A function to be called when the response is
+ * @param {function(number, (string|Object), Function)} success A function to be called when the response is
* received. The success function will be called with:
*
* - {number} code [HTTP status code](http://en.wikipedia.org/wiki/List_of_HTTP_status_codes) of
@@ -104,6 +104,9 @@
* {@link angular.service.$xhr.error} service (or custom error callback).
* - {string|Object} response Response object as string or an Object if the response was in JSON
* format.
+ * - {function(string=)} responseHeaders A function that when called with a {string} header name,
+ * returns the value of that header or null if it does not exist; when called without
+ * arguments, returns an object containing every response header
* @param {function(number, (string|Object))} error A function to be called if the response code is
* not 2xx.. Accepts the same arguments as success, above.
*
@@ -198,7 +201,7 @@ angularServiceInject('$xhr', function($browser, $error, $log, $updateView){
post = toJson(post);
}
- $browser.xhr(method, url, post, function(code, response){
+ $browser.xhr(method, url, post, function(code, response, responseHeaders){
try {
if (isString(response)) {
if (response.match(/^\)\]\}',\n/)) response=response.substr(6);
@@ -207,9 +210,9 @@ angularServiceInject('$xhr', function($browser, $error, $log, $updateView){
}
}
if (200 <= code && code < 300) {
- success(code, response);
+ success(code, response, responseHeaders);
} else if (isFunction(error)) {
- error(code, response);
+ error(code, response, responseHeaders);
} else {
$error(
{method: method, url: url, data: post, success: success},