| 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 "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| 11 import 'dart:io'; | 11 import 'dart:io'; |
| 12 | 12 |
| 13 void main() { | 13 void main() { |
| 14 HttpServer.bind("127.0.0.1", 0).then((server) { | 14 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 15 server.listen((request) { | 15 server.listen((request) { |
| 16 request.response | 16 request.response |
| 17 ..writeln("first line") | 17 ..writeln("first line") |
| 18 ..write("") | 18 ..write("") |
| 19 ..writeln("second line") | 19 ..writeln("second line") |
| 20 ..close(); | 20 ..close(); |
| 21 }); | 21 }); |
| 22 | 22 |
| 23 HttpClient client = new HttpClient(); | 23 HttpClient client = new HttpClient(); |
| 24 client.get("127.0.0.1", server.port, "/") | 24 client.get("127.0.0.1", server.port, "/").then((HttpClientRequest request) { |
| 25 .then((HttpClientRequest request) { | 25 return request.close(); |
| 26 return request.close(); | 26 }).then((HttpClientResponse response) { |
| 27 }) | 27 List<int> body = new List(); |
| 28 .then((HttpClientResponse response) { | 28 response.listen(body.addAll, onDone: () { |
| 29 List<int> body = new List(); | 29 Expect.equals( |
| 30 response.listen(body.addAll, | 30 "first line\nsecond line\n", new String.fromCharCodes(body)); |
| 31 onDone: () { | 31 server.close(); |
| 32 Expect.equals("first line\nsecond line\n", | 32 }); |
| 33 new String.fromCharCodes(body)); | 33 }); |
| 34 server.close(); | |
| 35 }); | |
| 36 }); | |
| 37 }); | 34 }); |
| 38 } | 35 } |
| OLD | NEW |