Skip to content

Commit 29a0077

Browse files
donny-dontnex3
authored andcommitted
Modify context variable names and write docs (#133)
1 parent fc32f51 commit 29a0077

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

lib/browser_client.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ import 'src/response.dart';
2323
/// unable to directly set some headers, such as `content-length`. It is also
2424
/// unable to stream requests or responses; a request will only be sent and a
2525
/// response will only be returned once all the data is available.
26+
///
27+
/// You can control the underlying `dart:html` [HttpRequest] by adding values to
28+
/// [Request.context]:
29+
///
30+
/// * `"http.html.with_credentials"` is a boolean that defaults to `false`. If
31+
/// it's `true`, cross-site requests will include credentials such as cookies
32+
/// or authorization headers. See also [HttpRequest.withCredentials].
2633
class BrowserClient extends BaseClient {
2734
/// The currently active XHRs.
2835
///
@@ -38,7 +45,8 @@ class BrowserClient extends BaseClient {
3845
_xhrs.add(xhr);
3946
_openHttpRequest(xhr, request.method, request.url.toString(), asynch: true);
4047
xhr.responseType = 'blob';
41-
xhr.withCredentials = request.context['html.withCredentials'] ?? false;
48+
xhr.withCredentials =
49+
request.context['http.html.with_credentials'] ?? false;
4250
request.headers.forEach(xhr.setRequestHeader);
4351

4452
var completer = new Completer<Response>();

lib/src/io_client.dart

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ import 'response.dart';
1515
/// A `dart:io`-based HTTP client.
1616
///
1717
/// This is the default client when running on the command line.
18+
///
19+
/// You can control the underlying `dart:io` [HttpRequest] by adding values to
20+
/// [Request.context]:
21+
///
22+
/// * `"http.io.follow_redirects"` is a boolean. If it's `true` (the default)
23+
/// then the request will automatically follow HTTP redirects. If it's
24+
/// `false`, the client will need to handle redirects manually. See also
25+
/// [HttpClientRequest.followRedirects].
26+
///
27+
/// * `"http.io.max_redirects"` is an integer that specifies the maximum number
28+
/// of redirects that will be followed if `follow_redirects` is `true`. If the
29+
/// site redirects more than this, [send] will throw a [ClientException]. It
30+
/// defaults to `5`. See also [HttpClientRequest.maxRedirects].
31+
///
32+
/// * `"http.io.persistent_connection"` is a boolean. If it's `true` (the
33+
/// default) the client will request that the TCP connection be kept alive
34+
/// after the request completes. See also
35+
/// [HttpClientRequest.persistentConnection].
1836
class IOClient extends BaseClient {
1937
/// The underlying `dart:io` HTTP client.
2038
HttpClient _inner;
@@ -28,9 +46,10 @@ class IOClient extends BaseClient {
2846
var context = request.context;
2947

3048
ioRequest
31-
..followRedirects = context['io.followRedirects'] ?? true
32-
..maxRedirects = context['io.maxRedirects'] ?? 5
33-
..persistentConnection = context['io.persistentConnection'] ?? true;
49+
..followRedirects = context['http.io.follow_redirects'] ?? true
50+
..maxRedirects = context['http.io.max_redirects'] ?? 5
51+
..persistentConnection =
52+
context['http.io.persistent_connection'] ?? true;
3453
request.headers.forEach((name, value) {
3554
ioRequest.headers.set(name, value);
3655
});

0 commit comments

Comments
 (0)