Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 05369c7

Browse files
mvuksanochirayuk
authored andcommitted
fix(Http): Fix NoSuchMethodError in Http when cache set to true and
update documentation about cache usage. Closes #1066
1 parent bdb5d07 commit 05369c7

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
@@ -408,36 +408,39 @@ class Http {
408408
return (parsed.scheme == originUrl.scheme && parsed.host == originUrl.host);
409409
}
410410

411-
/**
412-
* Returns a [Future<HttpResponse>] when the request is fulfilled.
413-
*
414-
* Named Parameters:
415-
* - method: HTTP method (e.g. 'GET', 'POST', etc)
416-
* - url: Absolute or relative URL of the resource being requested.
417-
* - data: Data to be sent as the request message data.
418-
* - params: Map of strings or objects which will be turned to
419-
* `?key1=value1&key2=value2` after the url. If the values are
420-
* not strings, they will be JSONified.
421-
* - headers: Map of strings or functions which return strings representing
422-
* HTTP headers to send to the server. If the return value of a function
423-
* is null, the header will not be sent.
424-
* - withCredentials: True if cross-site requests should use credentials such as cookies or
425-
* authorization headers; false otherwise. If not specified, defaults to false.
426-
* - xsrfHeaderName: TBI
427-
* - xsrfCookieName: TBI
428-
* - interceptors: Either a [HttpInterceptor] or a [HttpInterceptors]
429-
* - cache: Boolean or [Cache]. If true, the default cache will be used.
430-
* - timeout: deprecated
431-
*/
411+
/**
412+
* Returns a [Future<HttpResponse>] when the request is fulfilled.
413+
*
414+
* Named Parameters:
415+
* - method: HTTP method (e.g. 'GET', 'POST', etc)
416+
* - url: Absolute or relative URL of the resource being requested.
417+
* - data: Data to be sent as the request message data.
418+
* - params: Map of strings or objects which will be turned to
419+
* `?key1=value1&key2=value2` after the url. If the values are
420+
* not strings, they will be JSONified.
421+
* - headers: Map of strings or functions which return strings representing
422+
* HTTP headers to send to the server. If the return value of a function
423+
* is null, the header will not be sent.
424+
* - withCredentials: True if cross-site requests should use credentials such as cookies or
425+
* authorization headers; false otherwise. If not specified, defaults to false.
426+
* - xsrfHeaderName: XSRF header name sent with the request. If not specified
427+
* [defaults.xsrfHeaderName] is used.
428+
* - xsrfCookieName: XSRF cookie name. If not specified [defaults.xsrfCookieName] is used.
429+
* - interceptors: Either a [HttpInterceptor] or a [HttpInterceptors]
430+
* - cache: Boolean or [Cache]. If true, null or not specified at all, the default cache will be
431+
* used. If false, no cache will be used. If object of type [Cache] is provided, that object
432+
* will be used as cache.
433+
* - timeout: deprecated
434+
*/
432435
async.Future<HttpResponse> call({
433436
String url,
434437
String method,
435438
data,
436439
Map<String, dynamic> params,
437440
Map<String, dynamic> headers,
438441
bool withCredentials: false,
439-
xsrfHeaderName,
440-
xsrfCookieName,
442+
String xsrfHeaderName,
443+
String xsrfCookieName,
441444
interceptors,
442445
cache,
443446
timeout
@@ -479,7 +482,7 @@ class Http {
479482

480483
if (cache == false) {
481484
cache = null;
482-
} else if (cache == null) {
485+
} else if (cache == true || cache == null) {
483486
cache = defaults.cache;
484487
}
485488

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)