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

Commit

Permalink
feat(http): allow caching for JSONP requests
Browse files Browse the repository at this point in the history
Closes #1947
Closes #8356
  • Loading branch information
shahata authored and petebacondarwin committed Jul 29, 2014
1 parent 9025113 commit 3607c98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,8 @@ function $HttpProvider() {
promise.then(removePendingReq, removePendingReq);


if ((config.cache || defaults.cache) && config.cache !== false && config.method == 'GET') {
if ((config.cache || defaults.cache) && config.cache !== false &&
(config.method === 'GET' || config.method === 'JSONP')) {
cache = isObject(config.cache) ? config.cache
: isObject(defaults.cache) ? defaults.cache
: defaultCache;
Expand Down
12 changes: 12 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,18 @@ describe('$http', function() {
expect(callback.mostRecentCall.args[0]).toBe('content');
}));

it('should cache JSONP request when cache is provided', inject(function($rootScope) {
$httpBackend.expect('JSONP', '/url?cb=JSON_CALLBACK').respond('content');
$http({method: 'JSONP', url: '/url?cb=JSON_CALLBACK', cache: cache});
$httpBackend.flush();

$http({method: 'JSONP', url: '/url?cb=JSON_CALLBACK', cache: cache}).success(callback);
$rootScope.$digest();

expect(callback).toHaveBeenCalledOnce();
expect(callback.mostRecentCall.args[0]).toBe('content');
}));

it('should cache request when cache is provided and no method specified', function () {
doFirstCacheRequest();

Expand Down

0 comments on commit 3607c98

Please sign in to comment.