| 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:isolate"; | 5 import "dart:isolate"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 void testNoBody(int totalConnections, bool explicitContentLength) { | 8 void testNoBody(int totalConnections, bool explicitContentLength) { |
| 9 var errors = 0; | 9 var errors = 0; |
| 10 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) { | 10 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 client.close(); | 192 client.close(); |
| 193 server.close(); | 193 server.close(); |
| 194 } | 194 } |
| 195 }); | 195 }); |
| 196 }) | 196 }) |
| 197 .catchError((e) => Expect.fail("Unexpected error $e")); | 197 .catchError((e) => Expect.fail("Unexpected error $e")); |
| 198 } | 198 } |
| 199 }); | 199 }); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void testHttp10() { | |
| 203 HttpServer.bind("127.0.0.1", 0, 5).then((server) { | |
| 204 server.listen( | |
| 205 (HttpRequest request) { | |
| 206 Expect.isNull(request.headers.value('content-length')); | |
| 207 Expect.equals(-1, request.contentLength); | |
| 208 var response = request.response; | |
| 209 response.contentLength = 0; | |
| 210 Expect.equals("1.0", request.protocolVersion); | |
| 211 response.done | |
| 212 .then((_) => Expect.fail("Unexpected response completion")) | |
| 213 .catchError((e) => Expect.isTrue(e.error is HttpException)); | |
| 214 response.addString("x"); | |
| 215 response.close(); | |
| 216 Expect.throws(() => response.addString("x"), | |
| 217 (e) => e is StateError); | |
| 218 }, | |
| 219 onError: (e) => Expect.fail("Unexpected error $e")); | |
| 220 | |
| 221 Socket.connect("127.0.0.1", server.port).then((socket) { | |
| 222 socket.addString("GET / HTTP/1.0\r\n\r\n"); | |
| 223 socket.close(); | |
| 224 socket.listen( | |
| 225 (d) { }, | |
| 226 onDone: () { | |
| 227 socket.destroy(); | |
| 228 server.close(); | |
| 229 }); | |
| 230 }); | |
| 231 }); | |
| 232 } | |
| 233 | |
| 234 void main() { | 202 void main() { |
| 235 testNoBody(5, false); | 203 testNoBody(5, false); |
| 236 testNoBody(5, true); | 204 testNoBody(5, true); |
| 237 testBody(5, false); | 205 testBody(5, false); |
| 238 testBody(5, true); | 206 testBody(5, true); |
| 239 testBodyChunked(5, false); | 207 testBodyChunked(5, false); |
| 240 testBodyChunked(5, true); | 208 testBodyChunked(5, true); |
| 241 testHttp10(); | |
| 242 } | 209 } |
| OLD | NEW |