OLD | NEW |
| (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.test_util; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import 'package:shelf/shelf.dart'; | |
10 import 'package:shelf/src/util.dart'; | |
11 | |
12 // "hello," | |
13 const HELLO_BYTES = const [104, 101, 108, 108, 111, 44]; | |
14 | |
15 // " world" | |
16 const WORLD_BYTES = const [32, 119, 111, 114, 108, 100]; | |
17 | |
18 /// A simple, synchronous handler for [Request]. | |
19 /// | |
20 /// By default, replies with a status code 200, empty headers, and | |
21 /// `Hello from ${request.url.path}`. | |
22 Response syncHandler(Request request, {int statusCode, | |
23 Map<String, String> headers}) { | |
24 if (statusCode == null) statusCode = 200; | |
25 return new Response(statusCode, headers: headers, | |
26 body: 'Hello from ${request.url.path}'); | |
27 } | |
28 | |
29 /// Calls [syncHandler] and wraps the response in a [Future]. | |
30 Future<Response> asyncHandler(Request request) => | |
31 new Future(() => syncHandler(request)); | |
32 | |
33 /// Makes a simple GET request to [handler] and returns the result. | |
34 Future<Response> makeSimpleRequest(Handler handler) => | |
35 syncFuture(() => handler(_request)); | |
36 | |
37 final _request = new Request('GET', LOCALHOST_URI); | |
38 | |
39 final LOCALHOST_URI = Uri.parse('http://localhost/'); | |
OLD | NEW |