Skip to content

Commit b64327e

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 b64327e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/core_dom/http.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ 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, the default cache will be used. If false, no cache will
419+
* be used. If object of type [Cache] is provided, that object will be used as cache.
419420
* - timeout: deprecated
420421
*/
421422
async.Future<HttpResponse> call({
@@ -468,7 +469,7 @@ class Http {
468469

469470
if (cache == false) {
470471
cache = null;
471-
} else if (cache == null) {
472+
} else if (cache == true) {
472473
cache = defaults.cache;
473474
}
474475

test/core_dom/http_spec.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,21 @@ 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+
backend.expect('GET', '/url').respond(200, 'content-cache');
846+
http(method: 'GET', url: '/url');
847+
flush();
848+
849+
backend.expect('GET', '/url').respond();
850+
http(method: 'GET', url: '/url', cache: true).then(callback);
851+
flush();
852+
853+
expect(callback).toHaveBeenCalledOnce();
854+
expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content-cache');
855+
}));
841856
});
842857
});
843858

0 commit comments

Comments
 (0)