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

fix(Http): Fix NoSuchMethodError in Http #1075

Merged
merged 1 commit into from
Jun 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions lib/core_dom/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,36 +397,39 @@ class Http {
return (parsed.scheme == originUrl.scheme && parsed.host == originUrl.host);
}

/**
* Returns a [Future<HttpResponse>] 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<HttpResponse>] 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<HttpResponse> call({
String url,
String method,
data,
Map<String, dynamic> params,
Map<String, dynamic> headers,
bool withCredentials: false,
xsrfHeaderName,
xsrfCookieName,
String xsrfHeaderName,
String xsrfCookieName,
interceptors,
cache,
timeout
Expand Down Expand Up @@ -468,7 +471,7 @@ class Http {

if (cache == false) {
cache = null;
} else if (cache == null) {
} else if (cache == true || cache == null) {
cache = defaults.cache;
}

Expand Down
16 changes: 16 additions & 0 deletions test/core_dom/http_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}));
});
});

Expand Down