From da4f018706edb63b6fdbae80f918d1a9833d1f0f Mon Sep 17 00:00:00 2001
From: Natalie Weizenbaum <nweiz@google.com>
Date: Wed, 1 Apr 2015 13:56:33 -0700
Subject: [PATCH] Add support for shelf 0.6.0.

Closes #51

R=kevmoo@google.com

Review URL: https://codereview.chromium.org//1057653002
---
 CHANGELOG.md                      |  4 ++++
 lib/src/util/one_off_handler.dart | 10 ++++++++--
 pubspec.yaml                      |  2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d17ff12a..f91c39c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+### 0.12.0-beta.3
+
+* Add support for `shelf` `0.6.0`.
+
 ### 0.12.0-beta.2
 
 * Rename the package to `test`. The `unittest` package will continue to exist
diff --git a/lib/src/util/one_off_handler.dart b/lib/src/util/one_off_handler.dart
index 9994f46a..069d6818 100644
--- a/lib/src/util/one_off_handler.dart
+++ b/lib/src/util/one_off_handler.dart
@@ -36,8 +36,14 @@ class OneOffHandler {
 
   /// Dispatches [request] to the appropriate handler.
   _onRequest(shelf.Request request) {
-    // Skip the first component because it's always "/".
-    var components = p.url.split(request.url.path).skip(1).toList();
+    var components = p.url.split(request.url.path);
+
+    // For shelf < 0.6.0, the first component of the path is always "/". We can
+    // safely skip it.
+    if (components.isNotEmpty && components.first == "/") {
+      components.removeAt(0);
+    }
+
     if (components.isEmpty) return new shelf.Response.notFound(null);
 
     var handler = _handlers.remove(components.removeAt(0));
diff --git a/pubspec.yaml b/pubspec.yaml
index 7530234a..07ff763e 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -10,7 +10,7 @@ dependencies:
   args: '>=0.12.1 <0.14.0'
   http_parser: '^0.0.2'
   pool: '^1.0.0'
-  shelf: '^0.5.3'
+  shelf: '>=0.5.3 <0.7.0'
   shelf_static: '^0.2.0'
   shelf_web_socket: '^0.0.1'
   source_span: '^1.0.0'
-- 
GitLab