Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: pkg/shelf/test/test_util.dart

Issue 256753004: pkg/shelf: change helper method on Request and Response (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nevermind Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/shelf/test/shelf_io_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // "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
12 /// A simple, synchronous handler for [Request]. 18 /// A simple, synchronous handler for [Request].
13 /// 19 ///
14 /// By default, replies with a status code 200, empty headers, and 20 /// By default, replies with a status code 200, empty headers, and
15 /// `Hello from ${request.url.path}`. 21 /// `Hello from ${request.url.path}`.
16 Response syncHandler(Request request, {int statusCode, 22 Response syncHandler(Request request, {int statusCode,
17 Map<String, String> headers}) { 23 Map<String, String> headers}) {
18 if (statusCode == null) statusCode = 200; 24 if (statusCode == null) statusCode = 200;
19 return new Response(statusCode, headers: headers, 25 return new Response(statusCode, headers: headers,
20 body: 'Hello from ${request.url.path}'); 26 body: 'Hello from ${request.url.path}');
21 } 27 }
22 28
23 /// Calls [syncHandler] and wraps the response in a [Future]. 29 /// Calls [syncHandler] and wraps the response in a [Future].
24 Future<Response> asyncHandler(Request request) => 30 Future<Response> asyncHandler(Request request) =>
25 new Future(() => syncHandler(request)); 31 new Future(() => syncHandler(request));
26 32
27 /// Makes a simple GET request to [handler] and returns the result. 33 /// Makes a simple GET request to [handler] and returns the result.
28 Future<Response> makeSimpleRequest(Handler handler) => 34 Future<Response> makeSimpleRequest(Handler handler) =>
29 syncFuture(() => handler(_request)); 35 syncFuture(() => handler(_request));
30 36
31 final _request = new Request('GET', LOCALHOST_URI); 37 final _request = new Request('GET', LOCALHOST_URI);
32 38
33 final LOCALHOST_URI = Uri.parse('http://localhost/'); 39 final LOCALHOST_URI = Uri.parse('http://localhost/');
OLDNEW
« no previous file with comments | « pkg/shelf/test/shelf_io_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698