Add support for shelf 0.6.0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f7400b..12d2b50 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
* Bumped up minimum SDK to 1.7.0.
+* Added support for `shelf` 0.6.0.
+
## 0.2.1
* Removed `Uri` format checks now that the core libraries is more strict.
diff --git a/lib/src/static_handler.dart b/lib/src/static_handler.dart
index 73c50b1..3729fa9 100644
--- a/lib/src/static_handler.dart
+++ b/lib/src/static_handler.dart
@@ -65,12 +65,11 @@
}
}
+ var uri = request.requestedUri;
if (entityType == FileSystemEntityType.DIRECTORY &&
- !request.url.path.endsWith('/')) {
+ !uri.path.endsWith('/')) {
// when serving the default document for a directory, if the requested
// path doesn't end with '/', redirect to the path with a trailing '/'
- var uri = request.requestedUri;
- assert(!uri.path.endsWith('/'));
var location = new Uri(
scheme: uri.scheme,
userInfo: uri.userInfo,
diff --git a/pubspec.yaml b/pubspec.yaml
index 23cd9cd..e0104f0 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: shelf_static
-version: 0.2.2-dev
+version: 0.2.2
author: Kevin Moore <github@j832.com>
description: Static file server support for Shelf
homepage: https://github.com/kevmoo/shelf_static.dart
@@ -8,7 +8,7 @@
dependencies:
http_parser: '>=0.0.2+2 <0.1.0'
mime: '>=0.9.0 <0.10.0'
- shelf: '>=0.5.3 <0.6.0'
+ shelf: '>=0.5.7 <0.7.0'
dev_dependencies:
args: '>=0.12.0 <0.13.0'
path: '>=1.1.0 <2.0.0'
diff --git a/test/alternative_root_test.dart b/test/alternative_root_test.dart
index e89a7c4..f96207a 100644
--- a/test/alternative_root_test.dart
+++ b/test/alternative_root_test.dart
@@ -35,7 +35,7 @@
schedule(() {
var handler = createStaticHandler(d.defaultRoot);
- return makeRequest(handler, '/static/root.txt', scriptName: '/static')
+ return makeRequest(handler, '/static/root.txt', handlerPath: 'static')
.then((response) {
expect(response.statusCode, HttpStatus.OK);
expect(response.contentLength, 8);
@@ -49,7 +49,7 @@
var handler = createStaticHandler(d.defaultRoot);
return makeRequest(handler, '/static/files/with%20space.txt',
- scriptName: '/static').then((response) {
+ handlerPath: 'static').then((response) {
expect(response.statusCode, HttpStatus.OK);
expect(response.contentLength, 18);
expect(response.readAsString(), completion('with space content'));
@@ -62,7 +62,7 @@
var handler = createStaticHandler(d.defaultRoot);
return makeRequest(handler, '/static/files/with%20space.txt',
- scriptName: '/static').then((response) {
+ handlerPath: 'static').then((response) {
expect(response.statusCode, HttpStatus.OK);
expect(response.contentLength, 18);
expect(response.readAsString(), completion('with space content'));
@@ -75,7 +75,7 @@
var handler = createStaticHandler(d.defaultRoot);
return makeRequest(handler, '/static/files/test.txt',
- scriptName: '/static').then((response) {
+ handlerPath: 'static').then((response) {
expect(response.statusCode, HttpStatus.OK);
expect(response.contentLength, 16);
expect(response.readAsString(), completion('test txt content'));
@@ -87,8 +87,8 @@
schedule(() {
var handler = createStaticHandler(d.defaultRoot);
- return makeRequest(handler, '/static/not_here.txt', scriptName: '/static')
- .then((response) {
+ return makeRequest(handler, '/static/not_here.txt',
+ handlerPath: 'static').then((response) {
expect(response.statusCode, HttpStatus.NOT_FOUND);
});
});
diff --git a/test/test_util.dart b/test/test_util.dart
index 3583d64..c18ed64 100644
--- a/test/test_util.dart
+++ b/test/test_util.dart
@@ -6,43 +6,35 @@
import 'dart:async';
-import 'package:matcher/matcher.dart';
+import 'package:unittest/unittest.dart';
import 'package:path/path.dart' as p;
import 'package:shelf/shelf.dart';
import 'package:shelf_static/src/util.dart';
-import 'package:stack_trace/stack_trace.dart';
-
-/// Like [Future.sync], but wraps the Future in [Chain.track] as well.
-Future syncFuture(callback()) => Chain.track(new Future.sync(callback));
final p.Context _ctx = p.url;
/// Makes a simple GET request to [handler] and returns the result.
Future<Response> makeRequest(Handler handler, String path,
- {String scriptName, Map<String, String> headers}) {
- var rootedHandler = _rootHandler(scriptName, handler);
+ {String handlerPath, Map<String, String> headers}) {
+ var rootedHandler = _rootHandler(handlerPath, handler);
return new Future.sync(() => rootedHandler(_fromPath(path, headers)));
}
Request _fromPath(String path, Map<String, String> headers) =>
new Request('GET', Uri.parse('http://localhost' + path), headers: headers);
-Handler _rootHandler(String scriptName, Handler handler) {
- if (scriptName == null || scriptName.isEmpty) {
+Handler _rootHandler(String path, Handler handler) {
+ if (path == null || path.isEmpty) {
return handler;
}
- if (!scriptName.startsWith('/')) {
- throw new ArgumentError('scriptName must start with "/" or be empty');
- }
-
return (Request request) {
- if (!_ctx.isWithin(scriptName, request.requestedUri.path)) {
+ if (!_ctx.isWithin("/$path", request.requestedUri.path)) {
return new Response.notFound('not found');
}
- assert(request.scriptName.isEmpty);
+ assert(request.handlerPath == '/');
- var relativeRequest = request.change(scriptName: scriptName);
+ var relativeRequest = request.change(path: path);
return handler(relativeRequest);
};