Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Unified Diff: tests/standalone/io/http_connection_header_test.dart

Issue 10315002: Improve the handling of the connection header (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_connection_header_test.dart
diff --git a/tests/standalone/io/http_connection_header_test.dart b/tests/standalone/io/http_connection_header_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f581c9e3b0ae606d7540297cf9d30bbd81a8a402
--- /dev/null
+++ b/tests/standalone/io/http_connection_header_test.dart
@@ -0,0 +1,74 @@
+// Copyright (c) 2012, 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:isolate");
+#import("dart:io");
+
+void setConnectionHeaders(HttpHeaders headers) {
+ headers.add(HttpHeaders.CONNECTION, "my-connection-header1");
+ headers.add("My-Connection-Header1", "some-value1");
+ headers.add(HttpHeaders.CONNECTION, "my-connection-header2");
+ headers.add("My-Connection-Header2", "some-value2");
+}
+
+void checkExpectedConnectionHeaders(HttpHeaders headers,
+ bool persistentConnection) {
+ Expect.equals("some-value1", headers.value("My-Connection-Header1"));
+ Expect.equals("some-value2", headers.value("My-Connection-Header2"));
+ if (persistentConnection) {
+ Expect.equals(2, headers[HttpHeaders.CONNECTION].length);
Anders Johnsen 2012/05/02 07:37:58 This looks kind of shaky. Maybe change to a listEq
Søren Gjesse 2012/05/02 11:56:05 Added check of the actual values.
+ } else {
+ Expect.equals(3, headers[HttpHeaders.CONNECTION].length);
Anders Johnsen 2012/05/02 07:37:58 Ditto.
Søren Gjesse 2012/05/02 11:56:05 Ditto.
+ }
+}
+
+void test(int totalConnections, bool clientPersistentConnection) {
+ HttpServer server = new HttpServer();
+ server.onError = (e) => Expect.fail("Unexpected error $e");
+ server.listen("127.0.0.1", 0, totalConnections);
+ server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
+ // Check expected request.
+ Expect.equals(clientPersistentConnection, request.persistentConnection);
+ Expect.equals(clientPersistentConnection, response.persistentConnection);
+ checkExpectedConnectionHeaders(request.headers,
+ request.persistentConnection);
+
+ // Generate response. If the client signaled non-persistent
+ // connection the server should not need to set it.
+ if (request.persistentConnection) {
+ response.persistentConnection = false;
+ }
+ setConnectionHeaders(response.headers);
+ response.outputStream.close();
+ };
+
+ int count = 0;
+ HttpClient client = new HttpClient();
+ for (int i = 0; i < totalConnections; i++) {
+ HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
+ conn.onError = (e) => Expect.fail("Unexpected error $e");
+ conn.onRequest = (HttpClientRequest request) {
+ setConnectionHeaders(request.headers);
+ request.persistentConnection = clientPersistentConnection;
+ request.outputStream.close();
+ };
+ conn.onResponse = (HttpClientResponse response) {
+ Expect.isFalse(response.persistentConnection);
+ checkExpectedConnectionHeaders(response.headers,
+ response.persistentConnection);
+ count++;
+ if (count == totalConnections) {
+ client.shutdown();
+ server.close();
+ }
+ };
+ }
+}
+
+
+void main() {
+ test(2, false);
+ test(2, true);
+}
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698