OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 shelf.test_util; | 5 library shelf.test_util; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:shelf/shelf.dart'; | 9 import 'package:shelf/shelf.dart'; |
10 import 'package:shelf/src/util.dart'; | 10 import 'package:shelf/src/util.dart'; |
11 | 11 |
12 /// A simple, synchronous handler for [Request]. | 12 /// A simple, synchronous handler for [Request]. |
13 /// | 13 /// |
14 /// By default, replies with a status code 200, empty headers, and | 14 /// By default, replies with a status code 200, empty headers, and |
15 /// `Hello from ${request.pathInfo}`. | 15 /// `Hello from ${request.url.path}`. |
16 Response syncHandler(Request request, {int statusCode, | 16 Response syncHandler(Request request, {int statusCode, |
17 Map<String, String> headers}) { | 17 Map<String, String> headers}) { |
18 if (statusCode == null) statusCode = 200; | 18 if (statusCode == null) statusCode = 200; |
19 return new Response(statusCode, headers: headers, | 19 return new Response(statusCode, headers: headers, |
20 body: 'Hello from ${request.pathInfo}'); | 20 body: 'Hello from ${request.url.path}'); |
21 } | 21 } |
22 | 22 |
23 /// Calls [syncHandler] and wraps the response in a [Future]. | 23 /// Calls [syncHandler] and wraps the response in a [Future]. |
24 Future<Response> asyncHandler(Request request) => | 24 Future<Response> asyncHandler(Request request) => |
25 new Future(() => syncHandler(request)); | 25 new Future(() => syncHandler(request)); |
26 | 26 |
27 /// Makes a simple GET request to [handler] and returns the result. | 27 /// Makes a simple GET request to [handler] and returns the result. |
28 Future<Response> makeSimpleRequest(Handler handler) => | 28 Future<Response> makeSimpleRequest(Handler handler) => |
29 syncFuture(() => handler(_request)); | 29 syncFuture(() => handler(_request)); |
30 | 30 |
31 final _request = new Request('/', '', 'GET', '', '1.1', | 31 final _request = new Request('GET', LOCALHOST_URI); |
32 Uri.parse('http://localhost/'), {}); | 32 |
| 33 final LOCALHOST_URI = Uri.parse('http://localhost/'); |
OLD | NEW |