Files
sdk/tests/standalone_2/io/http_connection_header_test.dart
T
David Morgan fb0902a05d Revert "[dart:io] Preserve header case in http header _builds()"
This reverts commit af19f9638d.

Reason for revert: Breaks package:shelf tests.

Original change's description:
> [dart:io] Preserve header case in http header _builds()
> 
> Bug: https://github.com/dart-lang/sdk/issues/33501
> Change-Id: I57d9bba251b76314bf40b81d1b09bd4643dce4d2
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141911
> Commit-Queue: Zichang Guo <zichangguo@google.com>
> Reviewed-by: Siva Annamalai <asiva@google.com>
> Reviewed-by: Jonas Termansen <sortie@google.com>

TBR=sortie@google.com,asiva@google.com,zichangguo@google.com

Change-Id: I9c0418a256cb53e415ed0d5aeab84c4b0b4a161d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/33501
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142980
Reviewed-by: David Morgan <davidmorgan@google.com>
Commit-Queue: David Morgan <davidmorgan@google.com>
2020-04-09 10:38:29 +00:00

82 lines
2.9 KiB
Dart

// 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 "package:expect/expect.dart";
import "dart:isolate";
import "dart:io";
void setConnectionHeaders(HttpHeaders headers) {
headers.add(HttpHeaders.connectionHeader, "my-connection-header1");
headers.add("My-Connection-Header1", "some-value1");
headers.add(HttpHeaders.connectionHeader, "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"));
Expect.isTrue(headers[HttpHeaders.connectionHeader]
.any((value) => value.toLowerCase() == "my-connection-header1"));
Expect.isTrue(headers[HttpHeaders.connectionHeader]
.any((value) => value.toLowerCase() == "my-connection-header2"));
if (persistentConnection) {
Expect.equals(2, headers[HttpHeaders.connectionHeader].length);
} else {
Expect.equals(3, headers[HttpHeaders.connectionHeader].length);
Expect.isTrue(headers[HttpHeaders.connectionHeader]
.any((value) => value.toLowerCase() == "close"));
}
}
void test(int totalConnections, bool clientPersistentConnection) {
HttpServer.bind("127.0.0.1", 0).then((server) {
server.listen((HttpRequest request) {
// Check expected request.
Expect.equals(clientPersistentConnection, request.persistentConnection);
Expect.equals(
clientPersistentConnection, request.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) {
request.response.persistentConnection = false;
}
setConnectionHeaders(request.response.headers);
request.response.close();
});
int count = 0;
HttpClient client = new HttpClient();
for (int i = 0; i < totalConnections; i++) {
client
.get("127.0.0.1", server.port, "/")
.then((HttpClientRequest request) {
setConnectionHeaders(request.headers);
request.persistentConnection = clientPersistentConnection;
return request.close();
}).then((HttpClientResponse response) {
Expect.isFalse(response.persistentConnection);
checkExpectedConnectionHeaders(
response.headers, response.persistentConnection);
response.listen((_) {}, onDone: () {
count++;
if (count == totalConnections) {
client.close();
server.close();
}
});
});
}
});
}
void main() {
test(2, false);
test(2, true);
}