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

Side by Side Diff: lib/src/dir_handler.dart

Issue 2171743003: Add the package implementation. (Closed) Base URL: git@github.com:dart-lang/shelf_packages_handler.git@master
Patch Set: Code review changes Created 4 years, 5 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 | « lib/src/async_handler.dart ('k') | lib/src/package_config_handler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 library shelf_packages_handler.dir_handler;
6
7 import 'package:path/path.dart' as p;
8 import 'package:shelf/shelf.dart';
9
10 /// A utility handler that mounts a sub-handler beneath a directory name,
11 /// wherever that directory name appears in a URL.
12 ///
13 /// In practice, this is used to mount a [PackagesHandler] underneath
14 /// `packages/` directories.
15 class DirHandler {
16 /// The directory name to look for.
17 final String _name;
18
19 /// The inner handler to mount.
20 final Handler _inner;
21
22 DirHandler(this._name, this._inner);
23
24 /// The callback for handling a single request.
25 call(Request request) {
26 var segments = request.url.pathSegments;
27 for (var i = 0; i < segments.length; i++) {
28 if (segments[i] != _name) continue;
29 return _inner(request.change(path: p.url.joinAll(segments.take(i + 1))));
30 }
31
32 return new Response.notFound("Not found.");
33 }
34 }
OLDNEW
« no previous file with comments | « lib/src/async_handler.dart ('k') | lib/src/package_config_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698