OLD | NEW |
1 // Copyright (c) 2012, 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 // Regression test for http://code.google.com/p/dart/issues/detail?id=6393. | 5 // Regression test for http://code.google.com/p/dart/issues/detail?id=6393. |
6 | 6 |
7 import "dart:io"; | 7 import "dart:io"; |
8 import "dart:uri"; | 8 import "dart:uri"; |
9 | 9 |
10 var client = new HttpClient(); | 10 var client = new HttpClient(); |
11 var clientRequest; | 11 var clientRequest; |
12 | 12 |
13 void main() { | 13 void main() { |
14 HttpServer.bind("127.0.0.1", 0) | 14 HttpServer.bind("127.0.0.1", 0) |
15 .then((server) { | 15 .then((server) { |
16 server.listen( | 16 server.listen( |
17 (req) { | 17 (req) { |
18 req.pipe(req.response); | 18 req.pipe(req.response); |
19 }); | 19 }); |
20 | 20 |
21 client.openUrl("POST", Uri.parse("http://localhost:${server.port}/")) | 21 client.openUrl("POST", Uri.parse("http://localhost:${server.port}/")) |
22 .then((request) { | 22 .then((request) { |
23 // Keep a reference to the client request object. | 23 // Keep a reference to the client request object. |
24 clientRequest = request; | 24 clientRequest = request; |
25 request.add([0]); | 25 request.writeBytes([0]); |
26 return request.response; | 26 return request.response; |
27 }) | 27 }) |
28 .then((response) { | 28 .then((response) { |
29 // Wait with closing the client request until the response headers | 29 // Wait with closing the client request until the response headers |
30 // are done. | 30 // are done. |
31 clientRequest.close(); | 31 clientRequest.close(); |
32 response.listen( | 32 response.listen( |
33 (_) {}, | 33 (_) {}, |
34 onDone: () { | 34 onDone: () { |
35 client.close(); | 35 client.close(); |
36 server.close(); | 36 server.close(); |
37 }); | 37 }); |
38 }); | 38 }); |
39 }); | 39 }); |
40 } | 40 } |
OLD | NEW |