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

Commit eab5731

Browse files
shahatapetebacondarwin
authored andcommitted
feat(http): allow caching for JSONP requests
Closes #1947 Closes #8356
1 parent 986c446 commit eab5731

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ng/http.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,8 @@ function $HttpProvider() {
945945
promise.then(removePendingReq, removePendingReq);
946946

947947

948-
if ((config.cache || defaults.cache) && config.cache !== false && config.method == 'GET') {
948+
if ((config.cache || defaults.cache) && config.cache !== false &&
949+
(config.method === 'GET' || config.method === 'JSONP')) {
949950
cache = isObject(config.cache) ? config.cache
950951
: isObject(defaults.cache) ? defaults.cache
951952
: defaultCache;

test/ng/httpSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,18 @@ describe('$http', function() {
12171217
expect(callback.mostRecentCall.args[0]).toBe('content');
12181218
}));
12191219

1220+
it('should cache JSONP request when cache is provided', inject(function($rootScope) {
1221+
$httpBackend.expect('JSONP', '/url?cb=JSON_CALLBACK').respond('content');
1222+
$http({method: 'JSONP', url: '/url?cb=JSON_CALLBACK', cache: cache});
1223+
$httpBackend.flush();
1224+
1225+
$http({method: 'JSONP', url: '/url?cb=JSON_CALLBACK', cache: cache}).success(callback);
1226+
$rootScope.$digest();
1227+
1228+
expect(callback).toHaveBeenCalledOnce();
1229+
expect(callback.mostRecentCall.args[0]).toBe('content');
1230+
}));
1231+
12201232
it('should cache request when cache is provided and no method specified', function () {
12211233
doFirstCacheRequest();
12221234

0 commit comments

Comments
 (0)