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 import "dart:async"; | 5 import "dart:async"; |
| 6 import "dart:typed_data"; |
6 import "dart:io"; | 7 import "dart:io"; |
7 | 8 |
8 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
9 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
10 | 11 |
11 void testListenOn() { | 12 void testListenOn() { |
12 ServerSocket socket; | 13 ServerSocket socket; |
13 HttpServer server; | 14 HttpServer server; |
14 | 15 |
15 void test(void onDone()) { | 16 void test(void onDone()) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 socket.close(); | 104 socket.close(); |
104 socket.listen(null); | 105 socket.listen(null); |
105 }); | 106 }); |
106 }); | 107 }); |
107 }, onError: (e) { | 108 }, onError: (e) { |
108 asyncEnd(); | 109 asyncEnd(); |
109 }); | 110 }); |
110 } | 111 } |
111 | 112 |
112 | 113 |
| 114 void testHttpServerClientClose() { |
| 115 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 116 runZoned(() { |
| 117 server.listen((request) { |
| 118 request.response.bufferOutput = false; |
| 119 request.response.add(new Uint8List(64 * 1024)); |
| 120 new Timer(const Duration(milliseconds: 100), () { |
| 121 request.response.close().then((_) { |
| 122 server.close(); |
| 123 }); |
| 124 }); |
| 125 }); |
| 126 }, onError: (e, s) { |
| 127 Expect.fail("Unexpected error: $e(${e.hashCode})\n$s"); |
| 128 }); |
| 129 var client = new HttpClient(); |
| 130 client.get("127.0.0.1", server.port, "/") |
| 131 .then((request) => request.close()) |
| 132 .then((response) { |
| 133 response.listen((_) {}).cancel(); |
| 134 }); |
| 135 }); |
| 136 } |
| 137 |
| 138 |
113 void main() { | 139 void main() { |
114 testListenOn(); | 140 testListenOn(); |
115 testHttpServerZone(); | 141 testHttpServerZone(); |
116 testHttpServerZoneError(); | 142 testHttpServerZoneError(); |
| 143 testHttpServerClientClose(); |
117 } | 144 } |
OLD | NEW |