Skip to content

Commit fc32f51

Browse files
donny-dontnex3
authored andcommitted
Documentation cleanup (#132)
1 parent 6d3d7c5 commit fc32f51

File tree

9 files changed

+33
-132
lines changed

9 files changed

+33
-132
lines changed

lib/browser_client.dart

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ import 'src/response.dart';
1919
/// A `dart:html`-based HTTP client that runs in the browser and is backed by
2020
/// XMLHttpRequests.
2121
///
22-
/// This client inherits some of the limitations of XMLHttpRequest. It ignores
23-
/// the [BaseRequest.contentLength], [BaseRequest.persistentConnection],
24-
/// [BaseRequest.followRedirects], and [BaseRequest.maxRedirects] fields. It is
25-
/// also unable to stream requests or responses; a request will only be sent and
26-
/// a response will only be returned once all the data is available.
22+
/// This client inherits some of the limitations of XMLHttpRequest. It is
23+
/// unable to directly set some headers, such as `content-length`. It is also
24+
/// unable to stream requests or responses; a request will only be sent and a
25+
/// response will only be returned once all the data is available.
2726
class BrowserClient extends BaseClient {
2827
/// The currently active XHRs.
2928
///
@@ -33,7 +32,6 @@ class BrowserClient extends BaseClient {
3332
/// Creates a new HTTP client.
3433
BrowserClient();
3534

36-
/// Sends an HTTP request and asynchronously returns the response.
3735
Future<Response> send(Request request) async {
3836
var bytes = await collectBytes(request.read());
3937
var xhr = new HttpRequest();
@@ -90,9 +88,6 @@ class BrowserClient extends BaseClient {
9088
request.open(method, url, async: asynch, user: user, password: password);
9189
}
9290

93-
/// Closes the client.
94-
///
95-
/// This terminates all active requests.
9691
void close() {
9792
for (var xhr in _xhrs) {
9893
xhr.abort();

lib/http.dart

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export 'src/response.dart';
2828
/// the request is complete. If you're planning on making multiple requests to
2929
/// the same server, you should use a single [Client] for all of those requests.
3030
///
31-
/// For more fine-grained control over the request, use [Request] instead.
31+
/// This automatically initializes a new [Client] and closes that client once
32+
/// the request is complete. If you're planning on making multiple requests to
33+
/// the same server, you should use a single [Client] for all of those requests.
3234
Future<Response> head(url, {Map<String, String> headers}) =>
3335
_withClient((client) => client.head(url, headers: headers));
3436

@@ -39,7 +41,9 @@ Future<Response> head(url, {Map<String, String> headers}) =>
3941
/// the request is complete. If you're planning on making multiple requests to
4042
/// the same server, you should use a single [Client] for all of those requests.
4143
///
42-
/// For more fine-grained control over the request, use [Request] instead.
44+
/// This automatically initializes a new [Client] and closes that client once
45+
/// the request is complete. If you're planning on making multiple requests to
46+
/// the same server, you should use a single [Client] for all of those requests.
4347
Future<Response> get(url, {Map<String, String> headers}) =>
4448
_withClient((client) => client.get(url, headers: headers));
4549

@@ -60,8 +64,9 @@ Future<Response> get(url, {Map<String, String> headers}) =>
6064
///
6165
/// [encoding] defaults to [UTF8].
6266
///
63-
/// For more fine-grained control over the request, use [Request] or
64-
/// [StreamedRequest] instead.
67+
/// This automatically initializes a new [Client] and closes that client once
68+
/// the request is complete. If you're planning on making multiple requests to
69+
/// the same server, you should use a single [Client] for all of those requests.
6570
Future<Response> post(url, body,
6671
{Map<String, String> headers, Encoding encoding}) =>
6772
_withClient((client) =>
@@ -84,8 +89,9 @@ Future<Response> post(url, body,
8489
///
8590
/// [encoding] defaults to [UTF8].
8691
///
87-
/// For more fine-grained control over the request, use [Request] or
88-
/// [StreamedRequest] instead.
92+
/// This automatically initializes a new [Client] and closes that client once
93+
/// the request is complete. If you're planning on making multiple requests to
94+
/// the same server, you should use a single [Client] for all of those requests.
8995
Future<Response> put(url, body,
9096
{Map<String, String> headers, Encoding encoding}) =>
9197
_withClient((client) =>
@@ -108,8 +114,9 @@ Future<Response> put(url, body,
108114
///
109115
/// [encoding] defaults to [UTF8].
110116
///
111-
/// For more fine-grained control over the request, use [Request] or
112-
/// [StreamedRequest] instead.
117+
/// This automatically initializes a new [Client] and closes that client once
118+
/// the request is complete. If you're planning on making multiple requests to
119+
/// the same server, you should use a single [Client] for all of those requests.
113120
Future<Response> patch(url, body,
114121
{Map<String, String> headers, Encoding encoding}) =>
115122
_withClient((client) =>
@@ -121,8 +128,6 @@ Future<Response> patch(url, body,
121128
/// This automatically initializes a new [Client] and closes that client once
122129
/// the request is complete. If you're planning on making multiple requests to
123130
/// the same server, you should use a single [Client] for all of those requests.
124-
///
125-
/// For more fine-grained control over the request, use [Request] instead.
126131
Future<Response> delete(url, {Map<String, String> headers}) =>
127132
_withClient((client) => client.delete(url, headers: headers));
128133

@@ -136,9 +141,6 @@ Future<Response> delete(url, {Map<String, String> headers}) =>
136141
/// This automatically initializes a new [Client] and closes that client once
137142
/// the request is complete. If you're planning on making multiple requests to
138143
/// the same server, you should use a single [Client] for all of those requests.
139-
///
140-
/// For more fine-grained control over the request and response, use [Request]
141-
/// instead.
142144
Future<String> read(url, {Map<String, String> headers}) =>
143145
_withClient((client) => client.read(url, headers: headers));
144146

@@ -152,9 +154,6 @@ Future<String> read(url, {Map<String, String> headers}) =>
152154
/// This automatically initializes a new [Client] and closes that client once
153155
/// the request is complete. If you're planning on making multiple requests to
154156
/// the same server, you should use a single [Client] for all of those requests.
155-
///
156-
/// For more fine-grained control over the request and response, use [Request]
157-
/// instead.
158157
Future<Uint8List> readBytes(url, {Map<String, String> headers}) =>
159158
_withClient((client) => client.readBytes(url, headers: headers));
160159

lib/src/base_client.dart

Lines changed: 3 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -13,136 +13,46 @@ import 'exception.dart';
1313
import 'request.dart';
1414
import 'response.dart';
1515

16-
/// The abstract base class for an HTTP client. This is a mixin-style class;
17-
/// subclasses only need to implement [send] and maybe [close], and then they
16+
/// The abstract base class for an HTTP client.
17+
///
18+
/// Subclasses only need to implement [send] and maybe [close], and then they
1819
/// get various convenience methods for free.
1920
abstract class BaseClient implements Client {
20-
/// Sends an HTTP HEAD request with the given headers to the given URL, which
21-
/// can be a [Uri] or a [String].
22-
///
23-
/// For more fine-grained control over the request, use [send] instead.
2421
Future<Response> head(url, {Map<String, String> headers}) =>
2522
send(new Request.head(url, headers: headers));
2623

27-
/// Sends an HTTP GET request with the given headers to the given URL, which
28-
/// can be a [Uri] or a [String].
29-
///
30-
/// For more fine-grained control over the request, use [send] instead.
3124
Future<Response> get(url, {Map<String, String> headers}) =>
3225
send(new Request.get(url, headers: headers));
3326

34-
/// Sends an HTTP POST request with the given headers and body to the given
35-
/// URL, which can be a [Uri] or a [String].
36-
///
37-
/// [body] sets the body of the request. It can be a [String], a [List<int>]
38-
/// or a [Map<String, String>]. If it's a String, it's encoded using
39-
/// [encoding] and used as the body of the request. The content-type of the
40-
/// request will default to "text/plain".
41-
///
42-
/// If [body] is a List, it's used as a list of bytes for the body of the
43-
/// request.
44-
///
45-
/// If [body] is a Map, it's encoded as form fields using [encoding]. The
46-
/// content-type of the request will be set to
47-
/// `"application/x-www-form-urlencoded"`; this cannot be overridden.
48-
///
49-
/// [encoding] defaults to UTF-8.
50-
///
51-
/// For more fine-grained control over the request, use [send] instead.
5227
Future<Response> post(url, body,
5328
{Map<String, String> headers, Encoding encoding}) =>
5429
send(new Request.post(url, body, headers: headers, encoding: encoding));
5530

56-
/// Sends an HTTP PUT request with the given headers and body to the given
57-
/// URL, which can be a [Uri] or a [String].
58-
///
59-
/// [body] sets the body of the request. It can be a [String], a [List<int>]
60-
/// or a [Map<String, String>]. If it's a String, it's encoded using
61-
/// [encoding] and used as the body of the request. The content-type of the
62-
/// request will default to "text/plain".
63-
///
64-
/// If [body] is a List, it's used as a list of bytes for the body of the
65-
/// request.
66-
///
67-
/// If [body] is a Map, it's encoded as form fields using [encoding]. The
68-
/// content-type of the request will be set to
69-
/// `"application/x-www-form-urlencoded"`; this cannot be overridden.
70-
///
71-
/// [encoding] defaults to UTF-8.
72-
///
73-
/// For more fine-grained control over the request, use [send] instead.
7431
Future<Response> put(url, body,
7532
{Map<String, String> headers, Encoding encoding}) =>
7633
send(new Request.put(url, body, headers: headers, encoding: encoding));
7734

78-
/// Sends an HTTP PATCH request with the given headers and body to the given
79-
/// URL, which can be a [Uri] or a [String].
80-
///
81-
/// [body] sets the body of the request. It can be a [String], a [List<int>]
82-
/// or a [Map<String, String>]. If it's a String, it's encoded using
83-
/// [encoding] and used as the body of the request. The content-type of the
84-
/// request will default to "text/plain".
85-
///
86-
/// If [body] is a List, it's used as a list of bytes for the body of the
87-
/// request.
88-
///
89-
/// If [body] is a Map, it's encoded as form fields using [encoding]. The
90-
/// content-type of the request will be set to
91-
/// `"application/x-www-form-urlencoded"`; this cannot be overridden.
92-
///
93-
/// [encoding] defaults to UTF-8.
94-
///
95-
/// For more fine-grained control over the request, use [send] instead.
9635
Future<Response> patch(url, body,
9736
{Map<String, String> headers, Encoding encoding}) =>
9837
send(new Request.patch(url, body, headers: headers, encoding: encoding));
9938

100-
/// Sends an HTTP DELETE request with the given headers to the given URL,
101-
/// which can be a [Uri] or a [String].
102-
///
103-
/// For more fine-grained control over the request, use [send] instead.
10439
Future<Response> delete(url, {Map<String, String> headers}) =>
10540
send(new Request.delete(url, headers: headers));
10641

107-
/// Sends an HTTP GET request with the given headers to the given URL, which
108-
/// can be a [Uri] or a [String], and returns a Future that completes to the
109-
/// body of the response as a String.
110-
///
111-
/// The Future will emit a [ClientException] if the response doesn't have a
112-
/// success status code.
113-
///
114-
/// For more fine-grained control over the request and response, use [send] or
115-
/// [get] instead.
11642
Future<String> read(url, {Map<String, String> headers}) async {
11743
var response = await get(url, headers: headers);
11844
_checkResponseSuccess(url, response);
11945

12046
return await response.readAsString();
12147
}
12248

123-
/// Sends an HTTP GET request with the given headers to the given URL, which
124-
/// can be a [Uri] or a [String], and returns a Future that completes to the
125-
/// body of the response as a list of bytes.
126-
///
127-
/// The Future will emit an [ClientException] if the response doesn't have a
128-
/// success status code.
129-
///
130-
/// For more fine-grained control over the request and response, use [send] or
131-
/// [get] instead.
13249
Future<Uint8List> readBytes(url, {Map<String, String> headers}) async {
13350
var response = await get(url, headers: headers);
13451
_checkResponseSuccess(url, response);
13552

13653
return await collectBytes(response.read());
13754
}
13855

139-
/// Sends an HTTP request and asynchronously returns the response.
140-
///
141-
/// Implementers should call [BaseRequest.finalize] to get the body of the
142-
/// request as a [ByteStream]. They shouldn't make any assumptions about the
143-
/// state of the stream; it could have data written to it asynchronously at a
144-
/// later point, or it could already be closed when it's returned. Any
145-
/// internal HTTP errors should be wrapped as [ClientException]s.
14656
Future<Response> send(Request request);
14757

14858
/// Throws an error if [response] is not successful.
@@ -156,8 +66,5 @@ abstract class BaseClient implements Client {
15666
throw new ClientException("$message.", url);
15767
}
15868

159-
/// Closes the client and cleans up any resources associated with it. It's
160-
/// important to close each client when it's done being used; failing to do so
161-
/// can cause the Dart process to hang.
16269
void close() {}
16370
}

lib/src/client.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ abstract class Client {
145145
/// Sends an HTTP request and asynchronously returns the response.
146146
Future<Response> send(Request request);
147147

148-
/// Closes the client and cleans up any resources associated with it. It's
149-
/// important to close each client when it's done being used; failing to do so
150-
/// can cause the Dart process to hang.
148+
/// Closes the client and cleans up any resources associated with it.
149+
///
150+
/// It's important to close each client when it's done being used; failing to
151+
/// do so can cause the Dart process to hang.
151152
void close();
152153
}

lib/src/exception.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
/// An exception caused by an error in a pkg/http client.
66
class ClientException implements Exception {
7+
/// Message describing the problem.
78
final String message;
89

910
/// The URL of the HTTP request or response that failed.
1011
final Uri uri;
1112

13+
/// Creates a [ClientException] explained in [message].
14+
///
15+
/// The [uri] points to the URL being requested if applicable.
1216
ClientException(this.message, [this.uri]);
1317

1418
String toString() => message;

lib/src/io_client.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class IOClient extends BaseClient {
2222
/// Creates a new HTTP client.
2323
IOClient([HttpClient inner]) : _inner = inner ?? new HttpClient();
2424

25-
/// Sends an HTTP request and asynchronously returns the response.
2625
Future<Response> send(Request request) async {
2726
try {
2827
var ioRequest = await _inner.openUrl(request.method, request.url);
@@ -57,8 +56,6 @@ class IOClient extends BaseClient {
5756
}
5857
}
5958

60-
/// Closes the client. This terminates all active connections. If a client
61-
/// remains unclosed, the Dart process may not terminate.
6259
void close() {
6360
if (_inner != null) _inner.close(force: true);
6461
_inner = null;

lib/src/multipart_body.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ class MultipartBody implements Body {
8484

8585
MultipartBody._(this._stream, this.contentLength);
8686

87-
/// Returns a [Stream] representing the body.
88-
///
89-
/// Can only be called once.
9087
Stream<List<int>> read() {
9188
if (_stream == null) {
9289
throw new StateError("The 'read' method can only be called once on a "

lib/src/pipeline.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Pipeline {
2020
/// The [Middleware] that is invoked at this stage.
2121
final Middleware _middleware;
2222

23+
/// Creates a [Pipeline].
2324
const Pipeline()
2425
: _parent = null,
2526
_middleware = null;

lib/src/utils.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ bool isPlainAscii(String string) => _asciiOnly.hasMatch(string);
4545

4646
/// Pipes all data and errors from [stream] into [sink].
4747
///
48-
/// Completes [Future] once [stream] is done. Unlike [store], [sink] remains
49-
/// open after [stream] is done.
48+
/// Completes [Future] once [stream] is done. [sink] remains open after [stream]
49+
/// is done.
5050
Future writeStreamToSink(Stream stream, EventSink sink) {
5151
var completer = new Completer();
5252
stream.listen(sink.add,

0 commit comments

Comments
 (0)