Skip to content

Commit a85e188

Browse files
committed
fix(Http): Fix NoSuchMethodError in Http when cache set to true and
update documentation about cache usage. Closes dart-archive#1066
1 parent daef71b commit a85e188

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/core_dom/http.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,9 @@ class Http {
415415
* - xsrfHeaderName: TBI
416416
* - xsrfCookieName: TBI
417417
* - interceptors: Either a [HttpInterceptor] or a [HttpInterceptors]
418-
* - cache: Boolean or [Cache]. If true, the default cache will be used.
418+
* - cache: Boolean or [Cache]. If true or not specified at all, the default cache will be used.
419+
* If false, no cache will be used. If object of type [Cache] is provided, that object will
420+
* be used as cache.
419421
* - timeout: deprecated
420422
*/
421423
async.Future<HttpResponse> call({
@@ -468,7 +470,7 @@ class Http {
468470

469471
if (cache == false) {
470472
cache = null;
471-
} else if (cache == null) {
473+
} else if (cache == true || cache == null) {
472474
cache = defaults.cache;
473475
}
474476

test/core_dom/http_spec.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,22 @@ void main() {
838838
http(method: 'GET', url: '/url', cache: false);
839839
flush();
840840
}));
841+
842+
it('should use default cache if {cache: true} is passed in request config', async(() {
843+
http.defaults.cache = cache;
844+
845+
// Fill default cache.
846+
backend.expect('GET', '/url').respond(200, 'content-cache');
847+
http(method: 'GET', url: '/url', cache: true);
848+
flush();
849+
850+
// Serve request from default cache when {cache: true} is set.
851+
http(method: 'GET', url: '/url', cache: true).then(callback);
852+
microLeap();
853+
854+
expect(callback).toHaveBeenCalledOnce();
855+
expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content-cache');
856+
}));
841857
});
842858
});
843859

0 commit comments

Comments
 (0)