aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjankuca2013-08-29 18:52:30 -0700
committerIgor Minar2013-09-02 11:48:14 +0200
commit2a3212a0a333ee4c0640c6b6d63d3c5c34a81c70 (patch)
treed906d7a403345011951da2600b68872cc9b5b6ce
parent7a08a76875b5f1f86b129b4f253cd74a75e2658a (diff)
downloadangular.js-2a3212a0a333ee4c0640c6b6d63d3c5c34a81c70.tar.bz2
fix($http): allow empty responses to be cached
Closes #3809
-rw-r--r--src/ng/http.js4
-rw-r--r--test/ng/httpSpec.js14
2 files changed, 16 insertions, 2 deletions
diff --git a/src/ng/http.js b/src/ng/http.js
index 40ebfca2..85068ff6 100644
--- a/src/ng/http.js
+++ b/src/ng/http.js
@@ -706,7 +706,7 @@ function $HttpProvider() {
if (cache) {
cachedResp = cache.get(url);
- if (cachedResp) {
+ if (isDefined(cachedResp)) {
if (cachedResp.then) {
// cached request has already been sent, but there is no response yet
cachedResp.then(removePendingReq, removePendingReq);
@@ -726,7 +726,7 @@ function $HttpProvider() {
}
// if we won't have the response in cache, send the request to the backend
- if (!cachedResp) {
+ if (isUndefined(cachedResp)) {
$httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
config.withCredentials);
}
diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js
index 18be5826..7f49ca8c 100644
--- a/test/ng/httpSpec.js
+++ b/test/ng/httpSpec.js
@@ -896,6 +896,20 @@ describe('$http', function() {
});
+ it('should allow the cached value to be an empty string', function () {
+ cache.put('/abc', '');
+
+ callback.andCallFake(function (response, status, headers) {
+ expect(response).toBe('');
+ expect(status).toBe(200);
+ });
+
+ $http({method: 'GET', url: '/abc', cache: cache}).success(callback);
+ $rootScope.$digest();
+ expect(callback).toHaveBeenCalled();
+ });
+
+
it('should default to status code 200 and empty headers if cache contains a non-array element',
inject(function($rootScope) {
cache.put('/myurl', 'simple response');