aboutsummaryrefslogtreecommitdiffstats
path: root/src/service/xhr.cache.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.cache.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.cache.js')
-rw-r--r--src/service/xhr.cache.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/service/xhr.cache.js b/src/service/xhr.cache.js
index 256b936e..b3280101 100644
--- a/src/service/xhr.cache.js
+++ b/src/service/xhr.cache.js
@@ -22,8 +22,8 @@
* @param {string} method HTTP method.
* @param {string} url Destination URL.
* @param {(string|Object)=} post Request body.
- * @param {function(number, (string|Object))} success Response success callback.
- * @param {function(number, (string|Object))=} error Response error callback.
+ * @param {function(number, (string|Object), Function)} success Response success callback.
+ * @param {function(number, (string|Object), Function)} error Response error callback.
* @param {boolean=} [verifyCache=false] If `true` then a result is immediately returned from cache
* (if present) while a request is sent to the server for a fresh response that will update the
* cached entry. The `success` function will be called when the response is received.
@@ -55,9 +55,9 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $error, $log) {
if (dataCached = cache.data[url]) {
if (sync) {
- success(200, copy(dataCached.value));
+ success(200, copy(dataCached.value), copy(dataCached.headers));
} else {
- $defer(function() { success(200, copy(dataCached.value)); });
+ $defer(function() { success(200, copy(dataCached.value), copy(dataCached.headers)); });
}
if (!verifyCache)
@@ -70,20 +70,20 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $error, $log) {
} else {
inflight[url] = {successes: [success], errors: [error]};
cache.delegate(method, url, post,
- function(status, response) {
+ function(status, response, responseHeaders) {
if (status == 200)
- cache.data[url] = {value: response};
+ cache.data[url] = {value: response, headers: responseHeaders};
var successes = inflight[url].successes;
delete inflight[url];
forEach(successes, function(success) {
try {
- (success||noop)(status, copy(response));
+ (success||noop)(status, copy(response), responseHeaders);
} catch(e) {
$log.error(e);
}
});
},
- function(status, response) {
+ function(status, response, responseHeaders) {
var errors = inflight[url].errors,
successes = inflight[url].successes;
delete inflight[url];
@@ -91,7 +91,7 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $error, $log) {
forEach(errors, function(error, i) {
try {
if (isFunction(error)) {
- error(status, copy(response));
+ error(status, copy(response), copy(responseHeaders));
} else {
$error(
{method: method, url: url, data: post, success: successes[i]},