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

Side by Side Diff: pkg/shelf/lib/src/stack.dart

Issue 219283008: pkg/shelf (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cl nits Created 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/shelf/lib/src/response.dart ('k') | pkg/shelf/lib/src/string_scanner.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) 2014, 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.stack;
6
7 import 'handler.dart';
8 import 'middleware.dart';
9
10 /// A helper that makes it easy to compose a set of [Middleware] and a
11 /// [Handler].
12 ///
13 /// var handler = const Stack()
14 /// .addMiddleware(loggingMiddleware)
15 /// .addMiddleware(cachingMiddleware)
16 /// .addHandler(application);
17 class Stack {
18 final Stack _parent;
19 final Middleware _middleware;
20
21 const Stack()
22 : _middleware = null,
23 _parent = null;
24
25 Stack._(this._middleware, this._parent);
26
27 /// Returns a new [Stack] with [middleware] added to the existing set of
28 /// [Middleware].
29 ///
30 /// [middleware] will be the last [Middleware] to process a request and
31 /// the first to process a response.
32 Stack addMiddleware(Middleware middleware) =>
33 new Stack._(middleware, this);
34
35 /// Returns a new [Handler] with [handler] as the final processor of a
36 /// [Request] if all of the middleware in the stack have passed the request
37 /// through.
38 Handler addHandler(Handler handler) {
39 if (_middleware == null) return handler;
40 return _parent.addHandler(_middleware(handler));
41 }
42
43 /// Exposes this stack of [Middleware] as a single middleware instance.
44 Middleware get middleware => addHandler;
45 }
OLDNEW
« no previous file with comments | « pkg/shelf/lib/src/response.dart ('k') | pkg/shelf/lib/src/string_scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698