Index: tests/standalone/io/http_head_test.dart |
diff --git a/tests/standalone/io/http_head_test.dart b/tests/standalone/io/http_head_test.dart |
index 7880e2d3278ca7fb5a7a0f6113809df2669b9b30..215872ce5418620628c3a647577196c1f0b6eaf3 100644 |
--- a/tests/standalone/io/http_head_test.dart |
+++ b/tests/standalone/io/http_head_test.dart |
@@ -1,52 +1,47 @@ |
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
import "dart:io"; |
void testHEAD(int totalConnections) { |
- HttpServer server = new HttpServer(); |
- server.onError = (e) => Expect.fail("Unexpected error $e"); |
- server.listen("127.0.0.1", 0, backlog: totalConnections); |
- server.addRequestHandler( |
- (request) => request.path == "/test100", |
- (HttpRequest request, HttpResponse response) { |
- response.contentLength = 100; |
- response.outputStream.close(); |
- }); |
- server.addRequestHandler( |
- (request) => request.path == "/test200", |
- (HttpRequest request, HttpResponse response) { |
- response.contentLength = 200; |
- List<int> data = new List<int>.fixedLength(200); |
- response.outputStream.write(data); |
- response.outputStream.close(); |
+ HttpServer.bind().then((server) { |
+ server.listen((request) { |
+ var response = request.response; |
+ if (request.uri.path == "/test100") { |
+ response.contentLength = 100; |
+ response.close(); |
+ } else if (request.uri.path == "/test200") { |
+ response.contentLength = 200; |
+ List<int> data = new List<int>.fixedLength(200, fill: 0); |
+ response.add(data); |
+ response.close(); |
+ } else { |
+ assert(false); |
+ } |
}); |
- HttpClient client = new HttpClient(); |
+ HttpClient client = new HttpClient(); |
- int count = 0; |
- for (int i = 0; i < totalConnections; i++) { |
- HttpClientConnection conn; |
- int len = (i % 2 == 0) ? 100 : 200; |
- if (i % 2 == 0) { |
- conn = client.open("HEAD", "127.0.0.1", server.port, "/test$len"); |
- } else { |
- conn = client.open("HEAD", "127.0.0.1", server.port, "/test$len"); |
+ int count = 0; |
+ for (int i = 0; i < totalConnections; i++) { |
+ int len = (i % 2 == 0) ? 100 : 200; |
+ client.open("HEAD", "127.0.0.1", server.port, "/test$len") |
+ .then((request) => request.close()) |
+ .then((HttpClientResponse response) { |
+ Expect.equals(len, response.contentLength); |
+ response.listen( |
+ (_) => Expect.fail("Data from HEAD request"), |
+ onDone: () { |
+ count++; |
+ if (count == totalConnections) { |
+ client.close(); |
+ server.close(); |
+ } |
+ }); |
+ }); |
} |
- conn.onError = (e) => Expect.fail("Unexpected error $e"); |
- conn.onResponse = (HttpClientResponse response) { |
- Expect.equals(len, response.contentLength); |
- response.inputStream.onData = () => Expect.fail("Data from HEAD request"); |
- response.inputStream.onClosed = () { |
- count++; |
- if (count == totalConnections) { |
- client.shutdown(); |
- server.close(); |
- } |
- }; |
- }; |
- } |
+ }); |
} |
void main() { |