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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 socket.listen( | 224 socket.listen( |
225 (d) { }, | 225 (d) { }, |
226 onDone: () { | 226 onDone: () { |
227 socket.destroy(); | 227 socket.destroy(); |
228 server.close(); | 228 server.close(); |
229 }); | 229 }); |
230 }); | 230 }); |
231 }); | 231 }); |
232 } | 232 } |
233 | 233 |
| 234 void testSetContentLength() { |
| 235 HttpServer.bind().then((server) { |
| 236 server.listen( |
| 237 (HttpRequest request) { |
| 238 var response = request.response; |
| 239 Expect.isNull(response.headers.value('content-length')); |
| 240 Expect.equals(-1, response.contentLength); |
| 241 response.headers.set("content-length", 3); |
| 242 Expect.equals("3", response.headers.value('content-length')); |
| 243 Expect.equals(3, response.contentLength); |
| 244 response.addString("xxx"); |
| 245 response.close(); |
| 246 }); |
| 247 |
| 248 var client = new HttpClient(); |
| 249 client.get("127.0.0.1", server.port, "/") |
| 250 .then((request) => request.close()) |
| 251 .then((response) { |
| 252 response.listen( |
| 253 (_) { }, |
| 254 onDone: () { |
| 255 client.close(); |
| 256 server.close(); |
| 257 }); |
| 258 }); |
| 259 }); |
| 260 } |
| 261 |
234 void main() { | 262 void main() { |
235 testNoBody(5, false); | 263 testNoBody(5, false); |
236 testNoBody(5, true); | 264 testNoBody(5, true); |
237 testBody(5, false); | 265 testBody(5, false); |
238 testBody(5, true); | 266 testBody(5, true); |
239 testBodyChunked(5, false); | 267 testBodyChunked(5, false); |
240 testBodyChunked(5, true); | 268 testBodyChunked(5, true); |
241 testHttp10(); | 269 testHttp10(); |
| 270 testSetContentLength(); |
242 } | 271 } |
OLD | NEW |