Make `Handler` return a `FutureOr` (#79)
Fixes #78
- Change the signature from dynamic to FutureOr<Response> to match runtime expectations.
- Expand Doc comment.
- Bump min SDK version to first with FutureOr.
- Update test and scheduled_test dependencies to allow newer SDK.
- Drop Travis tests for older SDKs.
diff --git a/.travis.yml b/.travis.yml
index ed130f2..d412cc2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,9 +4,6 @@
- dev
- stable
- 1.22.1
- - 1.21.1
- - 1.20.1
- - 1.19.1
dart_task:
- test: --platform vm
@@ -27,18 +24,6 @@
dart_task: dartanalyzer
- dart: stable
dart_task: dartanalyzer
- exclude:
- # Exclude Firefox tests on SDKs before 1.22.0-dev.4 which are lacking fix
- # https://github.com/dart-lang/sdk/commit/7c3c297a8ad907f12bf12b96a21777421067fd18
- - dart: 1.21.1
- dart_task:
- test: --platform firefox -j 1
- - dart: 1.20.1
- dart_task:
- test: --platform firefox -j 1
- - dart: 1.19.1
- dart_task:
- test: --platform firefox -j 1
# Only building master means that we don't run two builds for each pull request.
branches:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9246811..dc3c6cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 0.7.0
+
+* Give a return type to the `Handler` typedef. This may cause static warnings
+ where there previously were none, but all handlers should have already been
+ returning a `Response` or `Future<Response>`.
+
## 0.6.8
* Add a `securityContext` parameter to `self_io.serve()`.
diff --git a/lib/src/handler.dart b/lib/src/handler.dart
index 4bb08e9..8ff2a89 100644
--- a/lib/src/handler.dart
+++ b/lib/src/handler.dart
@@ -1,14 +1,21 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'dart:async';
import 'request.dart';
+import 'response.dart';
-/// The signature of a function which handles a [Request].
+/// A function which handles a [Request].
+///
+/// For example a static file handler may read the requested URI from the
+/// filesystem and return it as the body of the [Response].
+///
+/// A [Handler] which wraps one or more other handlers to perform pre or post
+/// processing is knowns as a "middleware".
///
/// A [Handler] may receive a request directly from an HTTP server or it
-/// may be composed as part of a larger application.
-///
-/// Should return [Response] or [Future<Response>].
-//TODO(kevmoo): provide a more detailed explanation.
-typedef Handler(Request request);
+/// may have been touched by other middleware. Similarly the response may be
+/// directly returned by an HTTP server or have further processing done by other
+/// middleware.
+typedef FutureOr<Response> Handler(Request request);
diff --git a/pubspec.yaml b/pubspec.yaml
index 4ae3c8a..8d5281c 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,10 +1,10 @@
name: shelf
-version: 0.6.9-dev
+version: 0.7.0-dev
author: Dart Team <misc@dartlang.org>
description: Web Server Middleware for Dart
homepage: https://github.com/dart-lang/shelf
environment:
- sdk: '>=1.13.2 <2.0.0-dev.infinity'
+ sdk: '>=1.22.0 <2.0.0-dev.infinity'
dependencies:
async: '^1.10.0'
collection: '^1.5.0'
@@ -14,5 +14,5 @@
stream_channel: '^1.0.0'
dev_dependencies:
http: '>=0.9.2 <0.12.0'
- scheduled_test: '^0.12.0'
- test: '^0.12.7'
+ scheduled_test: '^0.12.11'
+ test: '^0.12.20'
diff --git a/test/create_middleware_test.dart b/test/create_middleware_test.dart
index bb4b245..c17bcab 100644
--- a/test/create_middleware_test.dart
+++ b/test/create_middleware_test.dart
@@ -230,7 +230,10 @@
});
}
-_failHandler(Request request) => fail('should never get here');
+Response _failHandler(Request request) {
+ fail('should never get here');
+ return null;
+}
final Response _middlewareResponse =
new Response.ok('middleware content', headers: {'from': 'middleware'});