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.
diff --git a/lib/src/message.dart b/lib/src/message.dart
index 1796fa8..b0414c9 100644
--- a/lib/src/message.dart
+++ b/lib/src/message.dart
@@ -12,7 +12,7 @@
import 'shelf_unmodifiable_map.dart';
import 'util.dart';
-Body getBody(Message message) => message._body;
+Body extractBody(Message message) => message._body;
/// The default set of headers for a message created with no body and no
/// explicit headers.
@@ -153,7 +153,7 @@
var sameEncoding = _sameEncoding(headers, body);
if (sameEncoding) {
if (body.contentLength == null ||
- getHeader(headers, 'content-length') == body.contentLength.toString()) {
+ findHeader(headers, 'content-length') == '${body.contentLength}') {
return headers ?? const ShelfUnmodifiableMap.empty();
} else if (body.contentLength == 0 &&
(headers == null || headers.isEmpty)) {
@@ -190,7 +190,7 @@
bool _sameEncoding(Map<String, String> headers, Body body) {
if (body.encoding == null) return true;
- var contentType = getHeader(headers, 'content-type');
+ var contentType = findHeader(headers, 'content-type');
if (contentType == null) return false;
var charset = MediaType.parse(contentType).parameters['charset'];
diff --git a/lib/src/middleware/logger.dart b/lib/src/middleware/logger.dart
index 444ef08..f9cb16d 100644
--- a/lib/src/middleware/logger.dart
+++ b/lib/src/middleware/logger.dart
@@ -28,7 +28,7 @@
var watch = Stopwatch()..start();
return Future.sync(() => innerHandler(request)).then((response) {
- var msg = _getMessage(startTime, response.statusCode,
+ var msg = _message(startTime, response.statusCode,
request.requestedUri, request.method, watch.elapsed);
logger(msg, false);
@@ -37,7 +37,7 @@
}, onError: (error, StackTrace stackTrace) {
if (error is HijackException) throw error;
- var msg = _getErrorMessage(startTime, request.requestedUri,
+ var msg = _errorMessage(startTime, request.requestedUri,
request.method, watch.elapsed, error, stackTrace);
logger(msg, true);
@@ -51,7 +51,7 @@
return query == '' ? '' : '?$query';
}
-String _getMessage(DateTime requestTime, int statusCode, Uri requestedUri,
+String _message(DateTime requestTime, int statusCode, Uri requestedUri,
String method, Duration elapsedTime) {
return '${requestTime.toIso8601String()} '
'${elapsedTime.toString().padLeft(15)} '
@@ -59,7 +59,7 @@
'${requestedUri.path}${_formatQuery(requestedUri.query)}';
}
-String _getErrorMessage(DateTime requestTime, Uri requestedUri, String method,
+String _errorMessage(DateTime requestTime, Uri requestedUri, String method,
Duration elapsedTime, Object error, StackTrace stack) {
var chain = Chain.current();
if (stack != null) {
diff --git a/lib/src/request.dart b/lib/src/request.dart
index 5e8461a..169f8d4 100644
--- a/lib/src/request.dart
+++ b/lib/src/request.dart
@@ -11,12 +11,7 @@
import 'message.dart';
import 'util.dart';
-/// A callback provided by a Shelf adapter that's used by [Request.hijack] to
-/// provide a [HijackCallback] with a socket.
-typedef _OnHijackCallback = void Function(
- void Function(StreamChannel<List<int>> channel) callback);
-
-/// Represents an HTTP request to be processed by a Shelf application.
+/// An HTTP request to be processed by a Shelf application.
class Request extends Message {
/// The URL path from the current handler to the requested resource, relative
/// to [handlerPath], plus any query parameters.
@@ -222,7 +217,7 @@
headers = updateMap(this.headers, headers);
context = updateMap(this.context, context);
- body ??= getBody(this);
+ body ??= extractBody(this);
var handlerPath = this.handlerPath;
if (path != null) handlerPath += path;
@@ -258,13 +253,10 @@
}
}
-/// A class containing a callback for [Request.hijack] that also tracks whether
-/// the callback has been called.
+/// A callback for [Request.hijack] and tracking of whether it has been called.
class _OnHijack {
- /// The callback.
- final _OnHijackCallback _callback;
+ final void Function(void Function(StreamChannel<List<int>>)) _callback;
- /// Whether [this] has been called.
bool called = false;
_OnHijack(this._callback);
diff --git a/lib/src/response.dart b/lib/src/response.dart
index ada9744..73b08e0 100644
--- a/lib/src/response.dart
+++ b/lib/src/response.dart
@@ -311,7 +311,7 @@
headers = updateMap(this.headers, headers);
context = updateMap(this.context, context);
- body ??= getBody(this);
+ body ??= extractBody(this);
return Response(statusCode, body: body, headers: headers, context: context);
}
diff --git a/lib/src/util.dart b/lib/src/util.dart
index 32a7643..c96903d 100644
--- a/lib/src/util.dart
+++ b/lib/src/util.dart
@@ -49,7 +49,7 @@
///
/// This works even if [headers] is `null`, or if it's not yet a
/// case-insensitive map.
-String getHeader(Map<String, String> headers, String name) {
+String findHeader(Map<String, String> headers, String name) {
if (headers == null) return null;
if (headers is ShelfUnmodifiableMap) return headers[name];
diff --git a/pubspec.yaml b/pubspec.yaml
index ff15faf..56642d6 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -2,7 +2,6 @@
version: 0.7.6-dev
description: >-
A model for web server middleware that encourages composition and easy reuse
-author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/shelf
environment: