OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
11 | 11 |
12 void main() { | 12 void main() { |
13 HttpServer.bind().then((server) { | 13 HttpServer.bind().then((server) { |
14 server.listen((request) { | 14 server.listen((request) { |
15 request.response | 15 request.response |
16 ..addString("first line\n") | 16 ..writeln("first line") |
17 ..addString("") | 17 ..write("") |
18 ..addString("second line\n") | 18 ..writeln("second line") |
19 ..close(); | 19 ..close(); |
20 }); | 20 }); |
21 | 21 |
22 HttpClient client = new HttpClient(); | 22 HttpClient client = new HttpClient(); |
23 client.get("127.0.0.1", server.port, "/") | 23 client.get("127.0.0.1", server.port, "/") |
24 .then((HttpClientRequest request) { | 24 .then((HttpClientRequest request) { |
25 return request.close(); | 25 return request.close(); |
26 }) | 26 }) |
27 .then((HttpClientResponse response) { | 27 .then((HttpClientResponse response) { |
28 List<int> body = new List(); | 28 List<int> body = new List(); |
29 response.listen(body.addAll, | 29 response.listen(body.addAll, |
30 onDone: () { | 30 onDone: () { |
31 Expect.equals("first line\nsecond line\n", | 31 Expect.equals("first line\nsecond line\n", |
32 new String.fromCharCodes(body)); | 32 new String.fromCharCodes(body)); |
33 server.close(); | 33 server.close(); |
34 }); | 34 }); |
35 }); | 35 }); |
36 }); | 36 }); |
37 } | 37 } |
OLD | NEW |