OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 var server = new HttpServer(); | 14 var server = new HttpServer(); |
15 server.listen("127.0.0.1", 0); | 15 server.listen("127.0.0.1", 0); |
16 server.defaultRequestHandler = (req, rsp) { | 16 server.defaultRequestHandler = (req, rsp) { |
17 req.inputStream.onData = () { | 17 req.inputStream.onData = () { |
18 req.inputStream.read(); | 18 req.inputStream.read(); |
19 rsp.outputStream.close(); | 19 rsp.outputStream.close(); |
20 }; | 20 }; |
21 }; | 21 }; |
22 | 22 |
23 var connection = client.openUrl( | 23 var connection = client.openUrl( |
24 "POST", | 24 "POST", |
25 new Uri.fromString("http://localhost:${server.port}/")); | 25 Uri.parse("http://localhost:${server.port}/")); |
26 connection.onRequest = (request) { | 26 connection.onRequest = (request) { |
27 // Keep a reference to the client request object. | 27 // Keep a reference to the client request object. |
28 clientRequest = request; | 28 clientRequest = request; |
29 request.outputStream.write([0]); | 29 request.outputStream.write([0]); |
30 }; | 30 }; |
31 connection.onResponse = (response) { | 31 connection.onResponse = (response) { |
32 response.inputStream.onClosed = () { | 32 response.inputStream.onClosed = () { |
33 // Wait with closing the client request until the response is done. | 33 // Wait with closing the client request until the response is done. |
34 clientRequest.outputStream.close(); | 34 clientRequest.outputStream.close(); |
35 client.shutdown(); | 35 client.shutdown(); |
36 server.close(); | 36 server.close(); |
37 }; | 37 }; |
38 }; | 38 }; |
39 } | 39 } |
OLD | NEW |