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

Commit 8e48c4f

Browse files
jankucaIgorMinar
authored andcommitted
fix($http): allow empty responses to be cached
Closes #3809
1 parent 44ad61e commit 8e48c4f

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
@@ -892,7 +892,7 @@ function $HttpProvider() {
892892

893893
if (cache) {
894894
cachedResp = cache.get(url);
895-
if (cachedResp) {
895+
if (isDefined(cachedResp)) {
896896
if (cachedResp.then) {
897897
// cached request has already been sent, but there is no response yet
898898
cachedResp.then(removePendingReq, removePendingReq);
@@ -912,7 +912,7 @@ function $HttpProvider() {
912912
}
913913

914914
// if we won't have the response in cache, send the request to the backend
915-
if (!cachedResp) {
915+
if (isUndefined(cachedResp)) {
916916
$httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
917917
config.withCredentials, config.responseType);
918918
}

test/ng/httpSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,20 @@ describe('$http', function() {
12481248
});
12491249

12501250

1251+
it('should allow the cached value to be an empty string', function () {
1252+
cache.put('/abc', '');
1253+
1254+
callback.andCallFake(function (response, status, headers) {
1255+
expect(response).toBe('');
1256+
expect(status).toBe(200);
1257+
});
1258+
1259+
$http({method: 'GET', url: '/abc', cache: cache}).success(callback);
1260+
$rootScope.$digest();
1261+
expect(callback).toHaveBeenCalled();
1262+
});
1263+
1264+
12511265
it('should default to status code 200 and empty headers if cache contains a non-array element',
12521266
inject(function($rootScope) {
12531267
cache.put('/myurl', 'simple response');

0 commit comments

Comments
 (0)