From 871740ce80bfc4e3903bdd8826b086a3c51e93c0 Mon Sep 17 00:00:00 2001 From: Don Date: Thu, 26 Oct 2017 17:39:11 -0700 Subject: [PATCH 1/3] Modify context variable names and write docs --- lib/browser_client.dart | 9 ++++++++- lib/src/io_client.dart | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/browser_client.dart b/lib/browser_client.dart index 3e6779bfa4..7db741b661 100644 --- a/lib/browser_client.dart +++ b/lib/browser_client.dart @@ -23,6 +23,12 @@ 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. +/// +/// [BrowserClient] allows setting values directly on the underlying +/// [HttpRequest] values through [Request.context]. +/// +/// * `http.html.with_credentials` is a boolean value, defaulting to `false` +/// that corresponds to [HttpRequest.withCredentials]. class BrowserClient extends BaseClient { /// The currently active XHRs. /// @@ -38,7 +44,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(); diff --git a/lib/src/io_client.dart b/lib/src/io_client.dart index e0f790bc0d..58bbb8a467 100644 --- a/lib/src/io_client.dart +++ b/lib/src/io_client.dart @@ -15,6 +15,16 @@ import 'response.dart'; /// A `dart:io`-based HTTP client. /// /// This is the default client when running on the command line. +/// +/// [IOClient] allows setting values directly on the underlying [HttpRequest] +/// through the [Request.context]. +/// +/// * `http.io.follow_redirects` is a boolean value, defaulting to `true` that +/// corresponds to [HttpRequest.followRedirects]. +/// * `http.io.max_redirects` is an integer value, defaulting to `5` that +/// corresponds to [HttpRequest.maxRedirects]. +/// * `http.io.persistent_connection` is a boolean value, defaulting to `true` +/// that corresponds to [HttpRequest.persistentConnection]. class IOClient extends BaseClient { /// The underlying `dart:io` HTTP client. HttpClient _inner; @@ -28,9 +38,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); }); From d0501f746a045b053af420968dfebed997ae96f0 Mon Sep 17 00:00:00 2001 From: Don Date: Thu, 26 Oct 2017 18:12:57 -0700 Subject: [PATCH 2/3] Address review comments --- lib/browser_client.dart | 8 +++++--- lib/src/io_client.dart | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/browser_client.dart b/lib/browser_client.dart index 7db741b661..5f45681fd8 100644 --- a/lib/browser_client.dart +++ b/lib/browser_client.dart @@ -25,10 +25,12 @@ import 'src/response.dart'; /// response will only be returned once all the data is available. /// /// [BrowserClient] allows setting values directly on the underlying -/// [HttpRequest] values through [Request.context]. +/// [HttpRequest] values through [Request.context] : /// -/// * `http.html.with_credentials` is a boolean value, defaulting to `false` -/// that corresponds to [HttpRequest.withCredentials]. +/// * `http.html.with_credentials` is a boolean value, defaulting to `false`. +/// If true then cross-site requests should use credentials such as cookies +/// or authorization headers. This corresponds to +/// [HttpRequest.withCredentials]. class BrowserClient extends BaseClient { /// The currently active XHRs. /// diff --git a/lib/src/io_client.dart b/lib/src/io_client.dart index 58bbb8a467..63a3b664a6 100644 --- a/lib/src/io_client.dart +++ b/lib/src/io_client.dart @@ -17,14 +17,19 @@ import 'response.dart'; /// This is the default client when running on the command line. /// /// [IOClient] allows setting values directly on the underlying [HttpRequest] -/// through the [Request.context]. +/// through the [Request.context] : /// -/// * `http.io.follow_redirects` is a boolean value, defaulting to `true` that -/// corresponds to [HttpRequest.followRedirects]. -/// * `http.io.max_redirects` is an integer value, defaulting to `5` that -/// corresponds to [HttpRequest.maxRedirects]. -/// * `http.io.persistent_connection` is a boolean value, defaulting to `true` -/// that corresponds to [HttpRequest.persistentConnection]. +/// * `http.io.follow_redirects` is a boolean value, defaulting to `true`. +/// If true then the request will automatically follow redirects; otherwise +/// the client will need to handle them explicitly. This corresponds to +/// [HttpClientRequest.followRedirects]. +/// * `http.io.max_redirects` is an integer value, defaulting to `5`. This +/// specifies the maximum number of redirects that will be followed. If +/// the site redirects more than this value a [ClientException] will be +/// thrown. This corresponds to [HttpClientRequest.maxRedirects]. +/// * `http.io.persistent_connection` is a boolean value, defaulting to `true`. +/// If true the client will request a persistent connection state. This +/// corresponds to [HttpClientRequest.persistentConnection]. class IOClient extends BaseClient { /// The underlying `dart:io` HTTP client. HttpClient _inner; From 0b9978e0ca768f3db035b3584b706585b01b4648 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 30 Oct 2017 18:33:20 -0700 Subject: [PATCH 3/3] Prose tweaks --- lib/browser_client.dart | 11 +++++------ lib/src/io_client.dart | 27 +++++++++++++++------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/browser_client.dart b/lib/browser_client.dart index 5f45681fd8..2932060ae0 100644 --- a/lib/browser_client.dart +++ b/lib/browser_client.dart @@ -24,13 +24,12 @@ import 'src/response.dart'; /// 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. /// -/// [BrowserClient] allows setting values directly on the underlying -/// [HttpRequest] values through [Request.context] : +/// You can control the underlying `dart:html` [HttpRequest] by adding values to +/// [Request.context]: /// -/// * `http.html.with_credentials` is a boolean value, defaulting to `false`. -/// If true then cross-site requests should use credentials such as cookies -/// or authorization headers. This corresponds to -/// [HttpRequest.withCredentials]. +/// * `"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. /// diff --git a/lib/src/io_client.dart b/lib/src/io_client.dart index 63a3b664a6..92b1b20cf3 100644 --- a/lib/src/io_client.dart +++ b/lib/src/io_client.dart @@ -16,20 +16,23 @@ import 'response.dart'; /// /// This is the default client when running on the command line. /// -/// [IOClient] allows setting values directly on the underlying [HttpRequest] -/// through the [Request.context] : +/// You can control the underlying `dart:io` [HttpRequest] by adding values to +/// [Request.context]: /// -/// * `http.io.follow_redirects` is a boolean value, defaulting to `true`. -/// If true then the request will automatically follow redirects; otherwise -/// the client will need to handle them explicitly. This corresponds to +/// * `"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 value, defaulting to `5`. This -/// specifies the maximum number of redirects that will be followed. If -/// the site redirects more than this value a [ClientException] will be -/// thrown. This corresponds to [HttpClientRequest.maxRedirects]. -/// * `http.io.persistent_connection` is a boolean value, defaulting to `true`. -/// If true the client will request a persistent connection state. This -/// corresponds to [HttpClientRequest.persistentConnection]. +/// +/// * `"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;