Skip to content

Commit c4351a0

Browse files
committed
Fixing review comments
1 parent 2cfad43 commit c4351a0

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/src/pipeline.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'client.dart';
6+
import 'handler.dart';
67
import 'middleware.dart';
78

89
/// A helper that makes it easy to compose a set of [Middleware] and a
@@ -11,9 +12,11 @@ import 'middleware.dart';
1112
/// var client = const Pipeline()
1213
/// .addMiddleware(loggingMiddleware)
1314
/// .addMiddleware(basicAuthMiddleware)
14-
/// .addHandler(new Client());
15+
/// .addClient(new Client());
1516
class Pipeline {
17+
/// The outer pipeline.
1618
final Pipeline _parent;
19+
/// The [Middleware] that is invoked at this stage.
1720
final Middleware _middleware;
1821

1922
const Pipeline()
@@ -36,6 +39,11 @@ class Pipeline {
3639
Client addClient(Client client) =>
3740
_middleware == null ? client : _parent.addClient(_middleware(client));
3841

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+
3947
/// Exposes this pipeline of [Middleware] as a single middleware instance.
4048
Middleware get middleware => addClient;
4149
}

test/pipeline_test.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:http/http.dart';
65
import 'package:test/test.dart';
7-
// \TODO REMOVE
8-
import 'package:http/src/pipeline.dart';
6+
7+
import 'package:http/http.dart';
98

109
void main() {
1110
test('compose middleware with Pipeline', () async {
12-
int accessLocation = 0;
11+
var accessLocation = 0;
1312

1413
var middlewareA = createMiddleware(requestHandler: (request) async {
1514
expect(accessLocation, 0);

0 commit comments

Comments
 (0)