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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 import 'dart:uri'; | 7 import 'dart:uri'; |
8 | 8 |
9 void main() { | 9 void main() { |
10 var client = new HttpClient(); | 10 var client = new HttpClient(); |
(...skipping 21 matching lines...) Expand all Loading... |
32 default: | 32 default: |
33 Expect.fail("Unexpected state"); | 33 Expect.fail("Unexpected state"); |
34 } | 34 } |
35 response.outputStream.close(); | 35 response.outputStream.close(); |
36 }; | 36 }; |
37 }; | 37 }; |
38 server.listen('127.0.0.1', 0); | 38 server.listen('127.0.0.1', 0); |
39 | 39 |
40 Future makeRequest(int n) { | 40 Future makeRequest(int n) { |
41 var completer = new Completer(); | 41 var completer = new Completer(); |
42 var url = new Uri.fromString("http://localhost:${server.port}"); | 42 var url = Uri.parse("http://localhost:${server.port}"); |
43 var connection = client.openUrl("POST", url); | 43 var connection = client.openUrl("POST", url); |
44 connection.onRequest = (HttpClientRequest request) { | 44 connection.onRequest = (HttpClientRequest request) { |
45 request.contentLength = n + 1; | 45 request.contentLength = n + 1; |
46 switch (n) { | 46 switch (n) { |
47 case 0: | 47 case 0: |
48 request.outputStream.writeFrom([65, 66, 67], 1, 1); | 48 request.outputStream.writeFrom([65, 66, 67], 1, 1); |
49 break; | 49 break; |
50 case 1: | 50 case 1: |
51 request.outputStream.writeFrom([65, 66, 67], 1); | 51 request.outputStream.writeFrom([65, 66, 67], 1); |
52 break; | 52 break; |
(...skipping 20 matching lines...) Expand all Loading... |
73 | 73 |
74 makeRequest(0).then((_) { | 74 makeRequest(0).then((_) { |
75 makeRequest(1).then((_) { | 75 makeRequest(1).then((_) { |
76 makeRequest(2).then((_) { | 76 makeRequest(2).then((_) { |
77 client.shutdown(); | 77 client.shutdown(); |
78 server.close(); | 78 server.close(); |
79 }); | 79 }); |
80 }); | 80 }); |
81 }); | 81 }); |
82 } | 82 } |
OLD | NEW |