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 /// A simple, synchronous handler for [Request]. |
| 13 /// |
| 14 /// By default, replies with a status code 200, empty headers, and |
| 15 /// `Hello from ${request.pathInfo}`. |
| 16 Response syncHandler(Request request, {int statusCode, |
| 17 Map<String, String> headers}) { |
| 18 if (statusCode == null) statusCode = 200; |
| 19 return new Response(statusCode, headers: headers, |
| 20 body: 'Hello from ${request.pathInfo}'); |
| 21 } |
| 22 |
| 23 /// Calls [syncHandler] and wraps the response in a [Future]. |
| 24 Future<Response> asyncHandler(Request request) => |
| 25 new Future(() => syncHandler(request)); |
| 26 |
| 27 /// Makes a simple GET request to [handler] and returns the result. |
| 28 Future<Response> makeSimpleRequest(Handler handler) => |
| 29 syncFuture(() => handler(_request)); |
| 30 |
| 31 final _request = new Request('/', '', 'GET', '', '1.1', |
| 32 Uri.parse('http://localhost/'), {}); |
OLD | NEW |