Skip to content

Commit d435c32

Browse files
authored
Small doc and style cleanup (#125)
- Fix some docs to be noun phrases for classes. - Remove some docs that are wholly redundant against the signature. - Remove an unnecessary private typedef. - Rename some methods that start with "get". - Remove author from pubspec. - Replace toString with interpolation to avoid an extra line break.
1 parent c52d4b5 commit d435c32

File tree

6 files changed

+13
-22
lines changed

6 files changed

+13
-22
lines changed

lib/src/message.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'body.dart';
1212
import 'shelf_unmodifiable_map.dart';
1313
import 'util.dart';
1414

15-
Body getBody(Message message) => message._body;
15+
Body extractBody(Message message) => message._body;
1616

1717
/// The default set of headers for a message created with no body and no
1818
/// explicit headers.
@@ -153,7 +153,7 @@ Map<String, String> _adjustHeaders(Map<String, String> headers, Body body) {
153153
var sameEncoding = _sameEncoding(headers, body);
154154
if (sameEncoding) {
155155
if (body.contentLength == null ||
156-
getHeader(headers, 'content-length') == body.contentLength.toString()) {
156+
findHeader(headers, 'content-length') == '${body.contentLength}') {
157157
return headers ?? const ShelfUnmodifiableMap.empty();
158158
} else if (body.contentLength == 0 &&
159159
(headers == null || headers.isEmpty)) {
@@ -190,7 +190,7 @@ Map<String, String> _adjustHeaders(Map<String, String> headers, Body body) {
190190
bool _sameEncoding(Map<String, String> headers, Body body) {
191191
if (body.encoding == null) return true;
192192

193-
var contentType = getHeader(headers, 'content-type');
193+
var contentType = findHeader(headers, 'content-type');
194194
if (contentType == null) return false;
195195

196196
var charset = MediaType.parse(contentType).parameters['charset'];

lib/src/middleware/logger.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Middleware logRequests({void Function(String message, bool isError) logger}) =>
2828
var watch = Stopwatch()..start();
2929

3030
return Future.sync(() => innerHandler(request)).then((response) {
31-
var msg = _getMessage(startTime, response.statusCode,
31+
var msg = _message(startTime, response.statusCode,
3232
request.requestedUri, request.method, watch.elapsed);
3333

3434
logger(msg, false);
@@ -37,7 +37,7 @@ Middleware logRequests({void Function(String message, bool isError) logger}) =>
3737
}, onError: (error, StackTrace stackTrace) {
3838
if (error is HijackException) throw error;
3939

40-
var msg = _getErrorMessage(startTime, request.requestedUri,
40+
var msg = _errorMessage(startTime, request.requestedUri,
4141
request.method, watch.elapsed, error, stackTrace);
4242

4343
logger(msg, true);
@@ -51,15 +51,15 @@ String _formatQuery(String query) {
5151
return query == '' ? '' : '?$query';
5252
}
5353

54-
String _getMessage(DateTime requestTime, int statusCode, Uri requestedUri,
54+
String _message(DateTime requestTime, int statusCode, Uri requestedUri,
5555
String method, Duration elapsedTime) {
5656
return '${requestTime.toIso8601String()} '
5757
'${elapsedTime.toString().padLeft(15)} '
5858
'${method.padRight(7)} [$statusCode] ' // 7 - longest standard HTTP method
5959
'${requestedUri.path}${_formatQuery(requestedUri.query)}';
6060
}
6161

62-
String _getErrorMessage(DateTime requestTime, Uri requestedUri, String method,
62+
String _errorMessage(DateTime requestTime, Uri requestedUri, String method,
6363
Duration elapsedTime, Object error, StackTrace stack) {
6464
var chain = Chain.current();
6565
if (stack != null) {

lib/src/request.dart

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ import 'hijack_exception.dart';
1111
import 'message.dart';
1212
import 'util.dart';
1313

14-
/// A callback provided by a Shelf adapter that's used by [Request.hijack] to
15-
/// provide a [HijackCallback] with a socket.
16-
typedef _OnHijackCallback = void Function(
17-
void Function(StreamChannel<List<int>> channel) callback);
18-
19-
/// Represents an HTTP request to be processed by a Shelf application.
14+
/// An HTTP request to be processed by a Shelf application.
2015
class Request extends Message {
2116
/// The URL path from the current handler to the requested resource, relative
2217
/// to [handlerPath], plus any query parameters.
@@ -222,7 +217,7 @@ class Request extends Message {
222217
headers = updateMap(this.headers, headers);
223218
context = updateMap(this.context, context);
224219

225-
body ??= getBody(this);
220+
body ??= extractBody(this);
226221

227222
var handlerPath = this.handlerPath;
228223
if (path != null) handlerPath += path;
@@ -258,13 +253,10 @@ class Request extends Message {
258253
}
259254
}
260255

261-
/// A class containing a callback for [Request.hijack] that also tracks whether
262-
/// the callback has been called.
256+
/// A callback for [Request.hijack] and tracking of whether it has been called.
263257
class _OnHijack {
264-
/// The callback.
265-
final _OnHijackCallback _callback;
258+
final void Function(void Function(StreamChannel<List<int>>)) _callback;
266259

267-
/// Whether [this] has been called.
268260
bool called = false;
269261

270262
_OnHijack(this._callback);

lib/src/response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class Response extends Message {
311311
headers = updateMap(this.headers, headers);
312312
context = updateMap(this.context, context);
313313

314-
body ??= getBody(this);
314+
body ??= extractBody(this);
315315

316316
return Response(statusCode, body: body, headers: headers, context: context);
317317
}

lib/src/util.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Map<String, String> addHeader(
4949
///
5050
/// This works even if [headers] is `null`, or if it's not yet a
5151
/// case-insensitive map.
52-
String getHeader(Map<String, String> headers, String name) {
52+
String findHeader(Map<String, String> headers, String name) {
5353
if (headers == null) return null;
5454
if (headers is ShelfUnmodifiableMap) return headers[name];
5555

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: shelf
22
version: 0.7.6-dev
33
description: >-
44
A model for web server middleware that encourages composition and easy reuse
5-
author: Dart Team <misc@dartlang.org>
65
homepage: https://github.com/dart-lang/shelf
76

87
environment:

0 commit comments

Comments
 (0)