File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
5
import 'client.dart' ;
6
+ import 'handler.dart' ;
6
7
import 'middleware.dart' ;
7
8
8
9
/// A helper that makes it easy to compose a set of [Middleware] and a
@@ -11,9 +12,11 @@ import 'middleware.dart';
11
12
/// var client = const Pipeline()
12
13
/// .addMiddleware(loggingMiddleware)
13
14
/// .addMiddleware(basicAuthMiddleware)
14
- /// .addHandler (new Client());
15
+ /// .addClient (new Client());
15
16
class Pipeline {
17
+ /// The outer pipeline.
16
18
final Pipeline _parent;
19
+ /// The [Middleware] that is invoked at this stage.
17
20
final Middleware _middleware;
18
21
19
22
const Pipeline ()
@@ -36,6 +39,11 @@ class Pipeline {
36
39
Client addClient (Client client) =>
37
40
_middleware == null ? client : _parent.addClient (_middleware (client));
38
41
42
+ /// Returns a new [Client] with [handler] as the final processor of a
43
+ /// [Request] if all of the middleware in the pipeline have passed the request
44
+ /// through.
45
+ Client addHandler (Handler handler) => addClient (new Client .handler (handler));
46
+
39
47
/// Exposes this pipeline of [Middleware] as a single middleware instance.
40
48
Middleware get middleware => addClient;
41
49
}
Original file line number Diff line number Diff line change 2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- import 'package:http/http.dart' ;
6
5
import 'package:test/test.dart' ;
7
- // \TODO REMOVE
8
- import 'package:http/src/pipeline .dart' ;
6
+
7
+ import 'package:http/http .dart' ;
9
8
10
9
void main () {
11
10
test ('compose middleware with Pipeline' , () async {
12
- int accessLocation = 0 ;
11
+ var accessLocation = 0 ;
13
12
14
13
var middlewareA = createMiddleware (requestHandler: (request) async {
15
14
expect (accessLocation, 0 );
You can’t perform that action at this time.
0 commit comments