Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: lib/src/util/one_off_handler.dart

Issue 1057653002: Add support for shelf 0.6.0. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.one_off_handler; 5 library test.one_off_handler;
6 6
7 import 'package:path/path.dart' as p; 7 import 'package:path/path.dart' as p;
8 import 'package:shelf/shelf.dart' as shelf; 8 import 'package:shelf/shelf.dart' as shelf;
9 9
10 /// A Shelf handler that provides support for one-time handlers. 10 /// A Shelf handler that provides support for one-time handlers.
(...skipping 18 matching lines...) Expand all
29 /// [handler] will be unmounted as soon as it receives a request. 29 /// [handler] will be unmounted as soon as it receives a request.
30 String create(shelf.Handler handler) { 30 String create(shelf.Handler handler) {
31 var path = _counter.toString(); 31 var path = _counter.toString();
32 _handlers[path] = handler; 32 _handlers[path] = handler;
33 _counter++; 33 _counter++;
34 return path; 34 return path;
35 } 35 }
36 36
37 /// Dispatches [request] to the appropriate handler. 37 /// Dispatches [request] to the appropriate handler.
38 _onRequest(shelf.Request request) { 38 _onRequest(shelf.Request request) {
39 // Skip the first component because it's always "/". 39 var components = p.url.split(request.url.path);
40 var components = p.url.split(request.url.path).skip(1).toList(); 40
41 // For shelf < 0.6.0, the first component of the path is always "/". We can
42 // safely skip it.
43 if (components.isNotEmpty && components.first == "/") {
44 components.removeAt(0);
45 }
46
41 if (components.isEmpty) return new shelf.Response.notFound(null); 47 if (components.isEmpty) return new shelf.Response.notFound(null);
42 48
43 var handler = _handlers.remove(components.removeAt(0)); 49 var handler = _handlers.remove(components.removeAt(0));
44 if (handler == null) return new shelf.Response.notFound(null); 50 if (handler == null) return new shelf.Response.notFound(null);
45 return handler(request); 51 return handler(request);
46 } 52 }
47 } 53 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698