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

Commit 2a3212a

Browse files
jankucaIgorMinar
authored andcommitted
fix($http): allow empty responses to be cached
Closes #3809
1 parent 7a08a76 commit 2a3212a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/ng/http.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ function $HttpProvider() {
706706

707707
if (cache) {
708708
cachedResp = cache.get(url);
709-
if (cachedResp) {
709+
if (isDefined(cachedResp)) {
710710
if (cachedResp.then) {
711711
// cached request has already been sent, but there is no response yet
712712
cachedResp.then(removePendingReq, removePendingReq);
@@ -726,7 +726,7 @@ function $HttpProvider() {
726726
}
727727

728728
// if we won't have the response in cache, send the request to the backend
729-
if (!cachedResp) {
729+
if (isUndefined(cachedResp)) {
730730
$httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
731731
config.withCredentials);
732732
}

test/ng/httpSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,20 @@ describe('$http', function() {
896896
});
897897

898898

899+
it('should allow the cached value to be an empty string', function () {
900+
cache.put('/abc', '');
901+
902+
callback.andCallFake(function (response, status, headers) {
903+
expect(response).toBe('');
904+
expect(status).toBe(200);
905+
});
906+
907+
$http({method: 'GET', url: '/abc', cache: cache}).success(callback);
908+
$rootScope.$digest();
909+
expect(callback).toHaveBeenCalled();
910+
});
911+
912+
899913
it('should default to status code 200 and empty headers if cache contains a non-array element',
900914
inject(function($rootScope) {
901915
cache.put('/myurl', 'simple response');

0 commit comments

Comments
 (0)