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

Commit d19d274

Browse files
committed
feat(http): allow caching for JSONP requests
Closes #1947
1 parent 583f37d commit d19d274

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ng/http.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,8 @@ function $HttpProvider() {
886886
promise.then(removePendingReq, removePendingReq);
887887

888888

889-
if ((config.cache || defaults.cache) && config.cache !== false && config.method == 'GET') {
889+
if ((config.cache || defaults.cache) && config.cache !== false &&
890+
(config.method === 'GET' || config.method === 'JSONP')) {
890891
cache = isObject(config.cache) ? config.cache
891892
: isObject(defaults.cache) ? defaults.cache
892893
: defaultCache;

test/ng/httpSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,18 @@ describe('$http', function() {
11061106
expect(callback.mostRecentCall.args[0]).toBe('content');
11071107
}));
11081108

1109+
it('should cache JSONP request when cache is provided', inject(function($rootScope) {
1110+
$httpBackend.expect('JSONP', '/url?cb=JSON_CALLBACK').respond('content');
1111+
$http({method: 'JSONP', url: '/url?cb=JSON_CALLBACK', cache: cache});
1112+
$httpBackend.flush();
1113+
1114+
$http({method: 'JSONP', url: '/url?cb=JSON_CALLBACK', cache: cache}).success(callback);
1115+
$rootScope.$digest();
1116+
1117+
expect(callback).toHaveBeenCalledOnce();
1118+
expect(callback.mostRecentCall.args[0]).toBe('content');
1119+
}));
1120+
11091121
it('should cache request when cache is provided and no method specified', function () {
11101122
doFirstCacheRequest();
11111123

0 commit comments

Comments
 (0)