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 | 5 |
6 import "dart:async"; | 6 import "dart:async"; |
7 import "dart:io"; | 7 import "dart:io"; |
8 import "dart:uri"; | 8 import "dart:uri"; |
9 | 9 |
10 void testHttp10Close(bool closeRequest) { | 10 void testHttp10Close(bool closeRequest) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 'data:${now.millisecondsSinceEpoch}\n\n'); | 58 'data:${now.millisecondsSinceEpoch}\n\n'); |
59 } catch (e) { | 59 } catch (e) { |
60 timer.cancel(); | 60 timer.cancel(); |
61 server.close(); | 61 server.close(); |
62 } | 62 } |
63 }); | 63 }); |
64 }; | 64 }; |
65 | 65 |
66 var client = new HttpClient(); | 66 var client = new HttpClient(); |
67 var connection = | 67 var connection = |
68 client.getUrl(new Uri.fromString("http://127.0.0.1:${server.port}")); | 68 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}")); |
69 connection.onResponse = (resp) { | 69 connection.onResponse = (resp) { |
70 int bytes = 0; | 70 int bytes = 0; |
71 resp.inputStream.onData = () { | 71 resp.inputStream.onData = () { |
72 bytes += resp.inputStream.read().length; | 72 bytes += resp.inputStream.read().length; |
73 if (bytes > 100) { | 73 if (bytes > 100) { |
74 client.shutdown(force: true); | 74 client.shutdown(force: true); |
75 } | 75 } |
76 }; | 76 }; |
77 }; | 77 }; |
78 connection.onError = (e) => Expect.isTrue(e is HttpException); | 78 connection.onError = (e) => Expect.isTrue(e is HttpException); |
79 } | 79 } |
80 | 80 |
81 main() { | 81 main() { |
82 testHttp10Close(false); | 82 testHttp10Close(false); |
83 testHttp10Close(true); | 83 testHttp10Close(true); |
84 testHttp11Close(false); | 84 testHttp11Close(false); |
85 testHttp11Close(true); | 85 testHttp11Close(true); |
86 testStreamResponse(); | 86 testStreamResponse(); |
87 } | 87 } |
OLD | NEW |