From 5b483324bd73955ed799b9ba363dbc2557e2b09a Mon Sep 17 00:00:00 2001 From: "deploy-test@travis-ci.org" Date: Wed, 28 May 2014 11:30:45 +1000 Subject: [PATCH] fix(Http): Fix NoSuchMethodError in Http when cache set to true and update documentation about cache usage. Closes #1066 --- lib/core_dom/http.dart | 51 +++++++++++++++++++----------------- test/core_dom/http_spec.dart | 16 +++++++++++ 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/lib/core_dom/http.dart b/lib/core_dom/http.dart index 40b98437d..411b237f1 100644 --- a/lib/core_dom/http.dart +++ b/lib/core_dom/http.dart @@ -397,27 +397,30 @@ class Http { return (parsed.scheme == originUrl.scheme && parsed.host == originUrl.host); } -/** - * Returns a [Future] when the request is fulfilled. - * - * Named Parameters: - * - method: HTTP method (e.g. 'GET', 'POST', etc) - * - url: Absolute or relative URL of the resource being requested. - * - data: Data to be sent as the request message data. - * - params: Map of strings or objects which will be turned to - * `?key1=value1&key2=value2` after the url. If the values are - * not strings, they will be JSONified. - * - headers: Map of strings or functions which return strings representing - * HTTP headers to send to the server. If the return value of a function - * is null, the header will not be sent. - * - withCredentials: True if cross-site requests should use credentials such as cookies or - * authorization headers; false otherwise. If not specified, defaults to false. - * - xsrfHeaderName: TBI - * - xsrfCookieName: TBI - * - interceptors: Either a [HttpInterceptor] or a [HttpInterceptors] - * - cache: Boolean or [Cache]. If true, the default cache will be used. - * - timeout: deprecated -*/ + /** + * Returns a [Future] when the request is fulfilled. + * + * Named Parameters: + * - method: HTTP method (e.g. 'GET', 'POST', etc) + * - url: Absolute or relative URL of the resource being requested. + * - data: Data to be sent as the request message data. + * - params: Map of strings or objects which will be turned to + * `?key1=value1&key2=value2` after the url. If the values are + * not strings, they will be JSONified. + * - headers: Map of strings or functions which return strings representing + * HTTP headers to send to the server. If the return value of a function + * is null, the header will not be sent. + * - withCredentials: True if cross-site requests should use credentials such as cookies or + * authorization headers; false otherwise. If not specified, defaults to false. + * - xsrfHeaderName: XSRF header name sent with the request. If not specified + * [defaults.xsrfHeaderName] is used. + * - xsrfCookieName: XSRF cookie name. If not specified [defaults.xsrfCookieName] is used. + * - interceptors: Either a [HttpInterceptor] or a [HttpInterceptors] + * - cache: Boolean or [Cache]. If true, null or not specified at all, the default cache will be + * used. If false, no cache will be used. If object of type [Cache] is provided, that object + * will be used as cache. + * - timeout: deprecated + */ async.Future call({ String url, String method, @@ -425,8 +428,8 @@ class Http { Map params, Map headers, bool withCredentials: false, - xsrfHeaderName, - xsrfCookieName, + String xsrfHeaderName, + String xsrfCookieName, interceptors, cache, timeout @@ -468,7 +471,7 @@ class Http { if (cache == false) { cache = null; - } else if (cache == null) { + } else if (cache == true || cache == null) { cache = defaults.cache; } diff --git a/test/core_dom/http_spec.dart b/test/core_dom/http_spec.dart index e31d75565..9a32f69f8 100644 --- a/test/core_dom/http_spec.dart +++ b/test/core_dom/http_spec.dart @@ -838,6 +838,22 @@ void main() { http(method: 'GET', url: '/url', cache: false); flush(); })); + + it('should use default cache if {cache: true} is passed in request config', async(() { + http.defaults.cache = cache; + + // Fill default cache. + backend.expect('GET', '/url').respond(200, 'content-cache'); + http(method: 'GET', url: '/url', cache: true); + flush(); + + // Serve request from default cache when {cache: true} is set. + http(method: 'GET', url: '/url', cache: true).then(callback); + microLeap(); + + expect(callback).toHaveBeenCalledOnce(); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content-cache'); + })); }); });