Skip to content

Commit 5b48332

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 e131da1 commit 5b48332

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

lib/core_dom/http.dart

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -397,36 +397,39 @@ class Http {
397397
return (parsed.scheme == originUrl.scheme && parsed.host == originUrl.host);
398398
}
399399

400-
/**
401-
* Returns a [Future<HttpResponse>] when the request is fulfilled.
402-
*
403-
* Named Parameters:
404-
* - method: HTTP method (e.g. 'GET', 'POST', etc)
405-
* - url: Absolute or relative URL of the resource being requested.
406-
* - data: Data to be sent as the request message data.
407-
* - params: Map of strings or objects which will be turned to
408-
* `?key1=value1&key2=value2` after the url. If the values are
409-
* not strings, they will be JSONified.
410-
* - headers: Map of strings or functions which return strings representing
411-
* HTTP headers to send to the server. If the return value of a function
412-
* is null, the header will not be sent.
413-
* - withCredentials: True if cross-site requests should use credentials such as cookies or
414-
* authorization headers; false otherwise. If not specified, defaults to false.
415-
* - xsrfHeaderName: TBI
416-
* - xsrfCookieName: TBI
417-
* - interceptors: Either a [HttpInterceptor] or a [HttpInterceptors]
418-
* - cache: Boolean or [Cache]. If true, the default cache will be used.
419-
* - timeout: deprecated
420-
*/
400+
/**
401+
* Returns a [Future<HttpResponse>] when the request is fulfilled.
402+
*
403+
* Named Parameters:
404+
* - method: HTTP method (e.g. 'GET', 'POST', etc)
405+
* - url: Absolute or relative URL of the resource being requested.
406+
* - data: Data to be sent as the request message data.
407+
* - params: Map of strings or objects which will be turned to
408+
* `?key1=value1&key2=value2` after the url. If the values are
409+
* not strings, they will be JSONified.
410+
* - headers: Map of strings or functions which return strings representing
411+
* HTTP headers to send to the server. If the return value of a function
412+
* is null, the header will not be sent.
413+
* - withCredentials: True if cross-site requests should use credentials such as cookies or
414+
* authorization headers; false otherwise. If not specified, defaults to false.
415+
* - xsrfHeaderName: XSRF header name sent with the request. If not specified
416+
* [defaults.xsrfHeaderName] is used.
417+
* - xsrfCookieName: XSRF cookie name. If not specified [defaults.xsrfCookieName] is used.
418+
* - interceptors: Either a [HttpInterceptor] or a [HttpInterceptors]
419+
* - cache: Boolean or [Cache]. If true, null or not specified at all, the default cache will be
420+
* used. If false, no cache will be used. If object of type [Cache] is provided, that object
421+
* will be used as cache.
422+
* - timeout: deprecated
423+
*/
421424
async.Future<HttpResponse> call({
422425
String url,
423426
String method,
424427
data,
425428
Map<String, dynamic> params,
426429
Map<String, dynamic> headers,
427430
bool withCredentials: false,
428-
xsrfHeaderName,
429-
xsrfCookieName,
431+
String xsrfHeaderName,
432+
String xsrfCookieName,
430433
interceptors,
431434
cache,
432435
timeout
@@ -468,7 +471,7 @@ class Http {
468471

469472
if (cache == false) {
470473
cache = null;
471-
} else if (cache == null) {
474+
} else if (cache == true || cache == null) {
472475
cache = defaults.cache;
473476
}
474477

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)