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

Commit 3607c98

Browse files
shahatapetebacondarwin
authored andcommitted
feat(http): allow caching for JSONP requests
Closes #1947 Closes #8356
1 parent 9025113 commit 3607c98

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
@@ -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

+12
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)