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

Side by Side 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: Addressed more comments Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4 //
5
6 #import("dart:isolate");
7 #import("dart:io");
8
9 void setConnectionHeaders(HttpHeaders headers) {
10 headers.add(HttpHeaders.CONNECTION, "my-connection-header1");
11 headers.add("My-Connection-Header1", "some-value1");
12 headers.add(HttpHeaders.CONNECTION, "my-connection-header2");
13 headers.add("My-Connection-Header2", "some-value2");
14 }
15
16 void checkExpectedConnectionHeaders(HttpHeaders headers,
17 bool persistentConnection) {
18 Expect.equals("some-value1", headers.value("My-Connection-Header1"));
19 Expect.equals("some-value2", headers.value("My-Connection-Header2"));
20 Expect.isTrue(headers[HttpHeaders.CONNECTION].some(
21 (value) => value.toLowerCase() == "my-connection-header1"));
22 Expect.isTrue(headers[HttpHeaders.CONNECTION].some(
23 (value) => value.toLowerCase() == "my-connection-header2"));
24 if (persistentConnection) {
25 Expect.equals(2, headers[HttpHeaders.CONNECTION].length);
26 } else {
27 Expect.equals(3, headers[HttpHeaders.CONNECTION].length);
28 Expect.isTrue(headers[HttpHeaders.CONNECTION].some(
29 (value) => value.toLowerCase() == "close"));
30 }
31 }
32
33 void test(int totalConnections, bool clientPersistentConnection) {
34 HttpServer server = new HttpServer();
35 server.onError = (e) => Expect.fail("Unexpected error $e");
36 server.listen("127.0.0.1", 0, totalConnections);
37 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
38 // Check expected request.
39 Expect.equals(clientPersistentConnection, request.persistentConnection);
40 Expect.equals(clientPersistentConnection, response.persistentConnection);
41 checkExpectedConnectionHeaders(request.headers,
42 request.persistentConnection);
43
44 // Generate response. If the client signaled non-persistent
45 // connection the server should not need to set it.
46 if (request.persistentConnection) {
47 response.persistentConnection = false;
48 }
49 setConnectionHeaders(response.headers);
50 response.outputStream.close();
51 };
52
53 int count = 0;
54 HttpClient client = new HttpClient();
55 for (int i = 0; i < totalConnections; i++) {
56 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
57 conn.onError = (e) => Expect.fail("Unexpected error $e");
58 conn.onRequest = (HttpClientRequest request) {
59 setConnectionHeaders(request.headers);
60 request.persistentConnection = clientPersistentConnection;
61 request.outputStream.close();
62 };
63 conn.onResponse = (HttpClientResponse response) {
64 Expect.isFalse(response.persistentConnection);
65 checkExpectedConnectionHeaders(response.headers,
66 response.persistentConnection);
67 count++;
68 if (count == totalConnections) {
69 client.shutdown();
70 server.close();
71 }
72 };
73 }
74 }
75
76
77 void main() {
78 test(2, false);
79 test(2, true);
80 }
OLDNEW
« 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