Skip to content

Commit 9fc6247

Browse files
authored
Clean up doc comment style (#315)
- Delete doc comments that add no new information. - Add some details to otherwise non-informative comments. - Consistently use a blank line following the first sentence. - Change some wording for style. - Remove unnecessary `new` in code examples.
1 parent 2ea7a5e commit 9fc6247

17 files changed

+126
-94
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ persistent connection by using a [Client][] rather than making one-off requests.
2828
If you do this, make sure to close the client when you're done:
2929

3030
```dart
31-
var client = new http.Client();
31+
var client = http.Client();
3232
try {
3333
var uriResponse = await client.post('https://example.com/whatsit/create',
3434
body: {'name': 'doodle', 'color': 'blue'});

lib/src/base_client.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import 'request.dart';
1313
import 'response.dart';
1414
import 'streamed_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
18-
/// get various convenience methods for free.
16+
/// The abstract base class for an HTTP client.
17+
///
18+
/// This is a mixin-style class; subclasses only need to implement [send] and
19+
/// maybe [close], and then they get various convenience methods for free.
1920
abstract class BaseClient implements Client {
2021
/// Sends an HTTP HEAD request with the given headers to the given URL, which
2122
/// can be a [Uri] or a [String].
@@ -189,9 +190,10 @@ abstract class BaseClient implements Client {
189190
throw ClientException('$message.', url);
190191
}
191192

192-
/// Closes the client and cleans up any resources associated with it. It's
193-
/// important to close each client when it's done being used; failing to do so
194-
/// can cause the Dart process to hang.
193+
/// Closes the client and cleans up any resources associated with it.
194+
///
195+
/// It's important to close each client when it's done being used; failing to
196+
/// do so can cause the Dart process to hang.
195197
@override
196198
void close() {}
197199
}

lib/src/base_request.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import 'utils.dart';
1717
/// over the request properties. However, usually it's easier to use convenience
1818
/// methods like [get] or [BaseClient.get].
1919
abstract class BaseRequest {
20-
/// The HTTP method of the request. Most commonly "GET" or "POST", less
21-
/// commonly "HEAD", "PUT", or "DELETE". Non-standard method names are also
22-
/// supported.
20+
/// The HTTP method of the request.
21+
///
22+
/// Most commonly "GET" or "POST", less commonly "HEAD", "PUT", or "DELETE".
23+
/// Non-standard method names are also supported.
2324
final String method;
2425

2526
/// The URL to which the request will be sent.
@@ -28,7 +29,7 @@ abstract class BaseRequest {
2829
/// The size of the request body, in bytes.
2930
///
3031
/// This defaults to `null`, which indicates that the size of the request is
31-
/// not known in advance.
32+
/// not known in advance. May not be assigned a negative value.
3233
int get contentLength => _contentLength;
3334
int _contentLength;
3435

@@ -41,6 +42,7 @@ abstract class BaseRequest {
4142
}
4243

4344
/// Whether a persistent connection should be maintained with the server.
45+
///
4446
/// Defaults to true.
4547
bool get persistentConnection => _persistentConnection;
4648
bool _persistentConnection = true;
@@ -51,6 +53,7 @@ abstract class BaseRequest {
5153
}
5254

5355
/// Whether the client should follow redirects while resolving this request.
56+
///
5457
/// Defaults to true.
5558
bool get followRedirects => _followRedirects;
5659
bool _followRedirects = true;
@@ -61,6 +64,7 @@ abstract class BaseRequest {
6164
}
6265

6366
/// The maximum number of redirects to follow when [followRedirects] is true.
67+
///
6468
/// If this number is exceeded the [BaseResponse] future will signal a
6569
/// [RedirectException]. Defaults to 5.
6670
int get maxRedirects => _maxRedirects;
@@ -74,22 +78,21 @@ abstract class BaseRequest {
7478
// TODO(nweiz): automatically parse cookies from headers
7579

7680
// TODO(nweiz): make this a HttpHeaders object
77-
/// The headers for this request.
7881
final Map<String, String> headers;
7982

80-
/// Whether the request has been finalized.
83+
/// Whether [finalize] has been called.
8184
bool get finalized => _finalized;
8285
bool _finalized = false;
8386

84-
/// Creates a new HTTP request.
8587
BaseRequest(this.method, this.url)
8688
: headers = LinkedHashMap(
8789
equals: (key1, key2) => key1.toLowerCase() == key2.toLowerCase(),
8890
hashCode: (key) => key.toLowerCase().hashCode);
8991

90-
/// Finalizes the HTTP request in preparation for it being sent. This freezes
91-
/// all mutable fields and returns a single-subscription [ByteStream] that
92-
/// emits the body of the request.
92+
/// Finalizes the HTTP request in preparation for it being sent.
93+
///
94+
/// Freezes all mutable fields and returns a single-subscription [ByteStream]
95+
/// that emits the body of the request.
9396
///
9497
/// The base implementation of this returns null rather than a [ByteStream];
9598
/// subclasses are responsible for creating the return value, which should be
@@ -128,7 +131,7 @@ abstract class BaseRequest {
128131
}
129132
}
130133

131-
// Throws an error if this request has been finalized.
134+
/// Throws an error if this request has been finalized.
132135
void _checkFinalized() {
133136
if (!finalized) return;
134137
throw StateError("Can't modify a finalized Request.");

lib/src/base_response.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class BaseResponse {
1212
/// The (frozen) request that triggered this response.
1313
final BaseRequest request;
1414

15-
/// The status code of the response.
15+
/// The HTTP status code for this response.
1616
final int statusCode;
1717

1818
/// The reason phrase associated with the status code.
@@ -26,16 +26,13 @@ abstract class BaseResponse {
2626
// TODO(nweiz): automatically parse cookies from headers
2727

2828
// TODO(nweiz): make this a HttpHeaders object.
29-
/// The headers for this response.
3029
final Map<String, String> headers;
3130

32-
/// Whether this response is a redirect.
3331
final bool isRedirect;
3432

3533
/// Whether the server requested that a persistent connection be maintained.
3634
final bool persistentConnection;
3735

38-
/// Creates a new HTTP response.
3936
BaseResponse(this.statusCode,
4037
{this.contentLength,
4138
this.request,

lib/src/boundary_characters.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// All character codes that are valid in multipart boundaries. This is the
6-
/// intersection of the characters allowed in the `bcharsnospace` production
7-
/// defined in [RFC 2046][] and those allowed in the `token` production
8-
/// defined in [RFC 1521][].
5+
/// All character codes that are valid in multipart boundaries.
6+
///
7+
/// This is the intersection of the characters allowed in the `bcharsnospace`
8+
/// production defined in [RFC 2046][] and those allowed in the `token`
9+
/// production defined in [RFC 1521][].
910
///
1011
/// [RFC 2046]: http://tools.ietf.org/html/rfc2046#section-5.1.1.
1112
/// [RFC 1521]: https://tools.ietf.org/html/rfc1521#section-4

lib/src/browser_client.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import 'byte_stream.dart';
1414
import 'exception.dart';
1515
import 'streamed_response.dart';
1616

17+
/// Create a [BrowserClient].
18+
///
1719
/// Used from conditional imports, matches the definition in `client_stub.dart`.
1820
BaseClient createClient() => BrowserClient();
1921

@@ -31,9 +33,6 @@ class BrowserClient extends BaseClient {
3133
/// These are aborted if the client is closed.
3234
final _xhrs = <HttpRequest>{};
3335

34-
/// Creates a new HTTP client.
35-
BrowserClient();
36-
3736
/// Whether to send credentials such as cookies or authorization headers for
3837
/// cross-site requests.
3938
///

lib/src/client.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ import 'response.dart';
1818
import 'streamed_response.dart';
1919

2020
/// The interface for HTTP clients that take care of maintaining persistent
21-
/// connections across multiple requests to the same server. If you only need to
22-
/// send a single request, it's usually easier to use [head], [get], [post],
23-
/// [put], [patch], or [delete] instead.
21+
/// connections across multiple requests to the same server.
22+
///
23+
/// If you only need to send a single request, it's usually easier to use
24+
/// [head], [get], [post], [put], [patch], or [delete] instead.
2425
///
2526
/// When creating an HTTP client class with additional functionality, you must
2627
/// extend [BaseClient] rather than [Client]. In most cases, you can wrap
2728
/// another instance of [Client] and add functionality on top of that. This
2829
/// allows all classes implementing [Client] to be mutually composable.
2930
abstract class Client {
30-
/// Creates a new client.
31+
/// Creates a new platform appropriate client.
3132
///
32-
/// Currently this will create an `IOClient` if `dart:io` is available and
33-
/// a `BrowserClient` if `dart:html` is available, otherwise it will throw
34-
/// an unsupported error.
33+
/// Creates an `IOClient` if `dart:io` is available and a `BrowserClient` if
34+
/// `dart:html` is available, otherwise it will throw an unsupported error.
3535
factory Client() => createClient();
3636

3737
/// Sends an HTTP HEAD request with the given headers to the given URL, which
@@ -140,8 +140,9 @@ abstract class Client {
140140
/// Sends an HTTP request and asynchronously returns the response.
141141
Future<StreamedResponse> send(BaseRequest request);
142142

143-
/// Closes the client and cleans up any resources associated with it. It's
144-
/// important to close each client when it's done being used; failing to do so
145-
/// can cause the Dart process to hang.
143+
/// Closes the client and cleans up any resources associated with it.
144+
///
145+
/// It's important to close each client when it's done being used; failing to
146+
/// do so can cause the Dart process to hang.
146147
void close();
147148
}

lib/src/io_client.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ import 'base_request.dart';
1212
import 'exception.dart';
1313
import 'streamed_response.dart';
1414

15+
/// Create an [IOClient].
16+
///
1517
/// Used from conditional imports, matches the definition in `client_stub.dart`.
1618
BaseClient createClient() => IOClient();
1719

1820
/// A `dart:io`-based HTTP client.
19-
///
20-
/// This is the default client when running on the command line.
2121
class IOClient extends BaseClient {
2222
/// The underlying `dart:io` HTTP client.
2323
HttpClient _inner;
2424

25-
/// Creates a new HTTP client.
2625
IOClient([HttpClient inner]) : _inner = inner ?? HttpClient();
2726

2827
/// Sends an HTTP request and asynchronously returns the response.
@@ -64,8 +63,10 @@ class IOClient extends BaseClient {
6463
}
6564
}
6665

67-
/// Closes the client. This terminates all active connections. If a client
68-
/// remains unclosed, the Dart process may not terminate.
66+
/// Closes the client.
67+
///
68+
/// Terminates all active connections. If a client remains unclosed, the Dart
69+
/// process may not terminate.
6970
@override
7071
void close() {
7172
if (_inner != null) {

lib/src/mock_client.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import 'streamed_response.dart';
1515
// server APIs, MockClient should conform to it.
1616

1717
/// A mock HTTP client designed for use when testing code that uses
18-
/// [BaseClient]. This client allows you to define a handler callback for all
19-
/// requests that are made through it so that you can mock a server without
20-
/// having to send real HTTP requests.
18+
/// [BaseClient].
19+
///
20+
/// This client allows you to define a handler callback for all requests that
21+
/// are made through it so that you can mock a server without having to send
22+
/// real HTTP requests.
2123
class MockClient extends BaseClient {
2224
/// The handler for receiving [StreamedRequest]s and sending
2325
/// [StreamedResponse]s.
@@ -66,7 +68,6 @@ class MockClient extends BaseClient {
6668
});
6769
});
6870

69-
/// Sends a request.
7071
@override
7172
Future<StreamedResponse> send(BaseRequest request) async {
7273
var bodyStream = request.finalize();
@@ -75,10 +76,13 @@ class MockClient extends BaseClient {
7576
}
7677

7778
/// A handler function that receives [StreamedRequest]s and sends
78-
/// [StreamedResponse]s. Note that [request] will be finalized.
79+
/// [StreamedResponse]s.
80+
///
81+
/// Note that [request] will be finalized.
7982
typedef MockClientStreamHandler = Future<StreamedResponse> Function(
8083
BaseRequest request, ByteStream bodyStream);
8184

82-
/// A handler function that receives [Request]s and sends [Response]s. Note that
83-
/// [request] will be finalized.
85+
/// A handler function that receives [Request]s and sends [Response]s.
86+
///
87+
/// Note that [request] will be finalized.
8488
typedef MockClientHandler = Future<Response> Function(Request request);

lib/src/multipart_file.dart

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,27 @@ import 'multipart_file_stub.dart'
1414
if (dart.library.io) 'multipart_file_io.dart';
1515
import 'utils.dart';
1616

17-
/// A file to be uploaded as part of a [MultipartRequest]. This doesn't need to
18-
/// correspond to a physical file.
17+
/// A file to be uploaded as part of a [MultipartRequest].
18+
///
19+
/// This doesn't need to correspond to a physical file.
1920
class MultipartFile {
2021
/// The name of the form field for the file.
2122
final String field;
2223

23-
/// The size of the file in bytes. This must be known in advance, even if this
24-
/// file is created from a [ByteStream].
24+
/// The size of the file in bytes.
25+
///
26+
/// This must be known in advance, even if this file is created from a
27+
/// [ByteStream].
2528
final int length;
2629

27-
/// The basename of the file. May be null.
30+
/// The basename of the file.
31+
///
32+
/// May be null.
2833
final String filename;
2934

30-
/// The content-type of the file. Defaults to `application/octet-stream`.
35+
/// The content-type of the file.
36+
///
37+
/// Defaults to `application/octet-stream`.
3138
final MediaType contentType;
3239

3340
/// The stream that will emit the file's contents.
@@ -37,9 +44,10 @@ class MultipartFile {
3744
bool get isFinalized => _isFinalized;
3845
bool _isFinalized = false;
3946

40-
/// Creates a new [MultipartFile] from a chunked [Stream] of bytes. The length
41-
/// of the file in bytes must be known in advance. If it's not, read the data
42-
/// from the stream and use [MultipartFile.fromBytes] instead.
47+
/// Creates a new [MultipartFile] from a chunked [Stream] of bytes.
48+
///
49+
/// The length of the file in bytes must be known in advance. If it's not,
50+
/// read the data from the stream and use [MultipartFile.fromBytes] instead.
4351
///
4452
/// [contentType] currently defaults to `application/octet-stream`, but in the
4553
/// future may be inferred from [filename].

0 commit comments

Comments
 (0)