OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; | |
6 import "dart:async"; | |
7 import "dart:io"; | |
8 import "dart:isolate"; | |
9 | |
10 class Server { | |
11 static Future<int> start() { | |
12 return HttpServer.bind("127.0.0.1", 0).then((server) { | |
13 server.listen((HttpRequest request) { | |
14 Timer.run(server.close); | |
15 }, onError: (e) { | |
16 String msg = "No server errors expected: $e"; | |
17 var trace = getAttachedStackTrace(e); | |
18 if (trace != null) msg += "\nStackTrace: $trace"; | |
19 Expect.fail(msg); | |
20 }); | |
21 return server.port; | |
22 }); | |
23 } | |
24 } | |
25 | |
26 class Client { | |
27 Client(int port) { | |
28 ReceivePort r = new ReceivePort(); | |
29 HttpClient client = new HttpClient(); | |
30 client.get("127.0.0.1", port, "/") | |
31 .then((HttpClientRequest request) { | |
32 return request.close(); | |
33 }) | |
34 .then((HttpClientResponse response) { | |
35 Expect.fail( | |
36 "Response should not be given, as not data was returned."); | |
37 }) | |
38 .catchError((e) { | |
39 r.close(); | |
40 }); | |
41 } | |
42 } | |
43 | |
44 main() { | |
45 Server.start().then((port) { | |
46 new Client(port); | |
47 }); | |
48 } | |
OLD | NEW |