Skip to content

Modify context variable naming #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 31, 2017
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
10 changes: 9 additions & 1 deletion lib/browser_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ import 'src/response.dart';
/// unable to directly set some headers, such as `content-length`. It is also
/// unable to stream requests or responses; a request will only be sent and a
/// response will only be returned once all the data is available.
///
/// You can control the underlying `dart:html` [HttpRequest] by adding values to
/// [Request.context]:
///
/// * `"http.html.with_credentials"` is a boolean that defaults to `false`. If
/// it's `true`, cross-site requests will include credentials such as cookies
/// or authorization headers. See also [HttpRequest.withCredentials].
class BrowserClient extends BaseClient {
/// The currently active XHRs.
///
Expand All @@ -38,7 +45,8 @@ class BrowserClient extends BaseClient {
_xhrs.add(xhr);
_openHttpRequest(xhr, request.method, request.url.toString(), asynch: true);
xhr.responseType = 'blob';
xhr.withCredentials = request.context['html.withCredentials'] ?? false;
xhr.withCredentials =
request.context['http.html.with_credentials'] ?? false;
request.headers.forEach(xhr.setRequestHeader);

var completer = new Completer<Response>();
Expand Down
25 changes: 22 additions & 3 deletions lib/src/io_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ import 'response.dart';
/// A `dart:io`-based HTTP client.
///
/// This is the default client when running on the command line.
///
/// You can control the underlying `dart:io` [HttpRequest] by adding values to
/// [Request.context]:
///
/// * `"http.io.follow_redirects"` is a boolean. If it's `true` (the default)
/// then the request will automatically follow HTTP redirects. If it's
/// `false`, the client will need to handle redirects manually. See also
/// [HttpClientRequest.followRedirects].
///
/// * `"http.io.max_redirects"` is an integer that specifies the maximum number
/// of redirects that will be followed if `follow_redirects` is `true`. If the
/// site redirects more than this, [send] will throw a [ClientException]. It
/// defaults to `5`. See also [HttpClientRequest.maxRedirects].
///
/// * `"http.io.persistent_connection"` is a boolean. If it's `true` (the
/// default) the client will request that the TCP connection be kept alive
/// after the request completes. See also
/// [HttpClientRequest.persistentConnection].
class IOClient extends BaseClient {
/// The underlying `dart:io` HTTP client.
HttpClient _inner;
Expand All @@ -28,9 +46,10 @@ class IOClient extends BaseClient {
var context = request.context;

ioRequest
..followRedirects = context['io.followRedirects'] ?? true
..maxRedirects = context['io.maxRedirects'] ?? 5
..persistentConnection = context['io.persistentConnection'] ?? true;
..followRedirects = context['http.io.follow_redirects'] ?? true
..maxRedirects = context['http.io.max_redirects'] ?? 5
..persistentConnection =
context['http.io.persistent_connection'] ?? true;
request.headers.forEach((name, value) {
ioRequest.headers.set(name, value);
});
Expand Down