OLD | NEW |
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.util.path_handler; | |
6 | |
7 import 'package:path/path.dart' as p; | 5 import 'package:path/path.dart' as p; |
8 import 'package:shelf/shelf.dart' as shelf; | 6 import 'package:shelf/shelf.dart' as shelf; |
9 | 7 |
10 /// A handler that routes to sub-handlers based on exact path prefixes. | 8 /// A handler that routes to sub-handlers based on exact path prefixes. |
11 class PathHandler { | 9 class PathHandler { |
12 /// A trie of path components to handlers. | 10 /// A trie of path components to handlers. |
13 final _paths = new _Node(); | 11 final _paths = new _Node(); |
14 | 12 |
15 /// The shelf handler. | 13 /// The shelf handler. |
16 shelf.Handler get handler => _onRequest; | 14 shelf.Handler get handler => _onRequest; |
(...skipping 30 matching lines...) Expand all Loading... |
47 return handler(request.change( | 45 return handler(request.change( |
48 path: p.url.joinAll(components.take(handlerIndex + 1)))); | 46 path: p.url.joinAll(components.take(handlerIndex + 1)))); |
49 } | 47 } |
50 } | 48 } |
51 | 49 |
52 /// A trie node. | 50 /// A trie node. |
53 class _Node { | 51 class _Node { |
54 shelf.Handler handler; | 52 shelf.Handler handler; |
55 final children = new Map<String, _Node>(); | 53 final children = new Map<String, _Node>(); |
56 } | 54 } |
OLD | NEW |