fix($http): allow empty responses to be cached

Closes #3809
This commit is contained in:
jankuca 2013-08-29 18:52:30 -07:00 committed by Igor Minar
parent 7a08a76875
commit 2a3212a0a3
2 changed files with 16 additions and 2 deletions

View file

@ -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);
}

View file

@ -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');