Test persistentConnection with large request bodies (#984)
diff --git a/pkgs/http_client_conformance_tests/lib/src/request_body_tests.dart b/pkgs/http_client_conformance_tests/lib/src/request_body_tests.dart
index fe12dd4..901f7f7 100644
--- a/pkgs/http_client_conformance_tests/lib/src/request_body_tests.dart
+++ b/pkgs/http_client_conformance_tests/lib/src/request_body_tests.dart
@@ -260,6 +260,47 @@
expect(serverReceivedBody.codeUnits, <int>[]);
});
+ test('client.send() with persistentConnection', () async {
+ // Do five requests to verify that the connection persistance logic is
+ // correct.
+ for (var i = 0; i < 5; ++i) {
+ final request = Request('POST', Uri.http(host, ''))
+ ..headers['Content-Type'] = 'text/plain; charset=utf-8'
+ ..persistentConnection = true
+ ..body = 'Hello World $i';
+
+ final response = await client.send(request);
+ expect(response.statusCode, 200);
+
+ final serverReceivedContentType = await httpServerQueue.next;
+ final serverReceivedBody = await httpServerQueue.next as String;
+
+ expect(serverReceivedContentType, ['text/plain; charset=utf-8']);
+ expect(serverReceivedBody, 'Hello World $i');
+ }
+ });
+
+ test('client.send() with persistentConnection and body >64K', () async {
+ // 64KiB is special for the HTTP network API:
+ // https://fetch.spec.whatwg.org/#http-network-or-cache-fetch
+ // See https://github.com/dart-lang/http/issues/977
+ final body = ''.padLeft(64 * 1024, 'XYZ');
+
+ final request = Request('POST', Uri.http(host, ''))
+ ..headers['Content-Type'] = 'text/plain; charset=utf-8'
+ ..persistentConnection = true
+ ..body = body;
+
+ final response = await client.send(request);
+ expect(response.statusCode, 200);
+
+ final serverReceivedContentType = await httpServerQueue.next;
+ final serverReceivedBody = await httpServerQueue.next as String;
+
+ expect(serverReceivedContentType, ['text/plain; charset=utf-8']);
+ expect(serverReceivedBody, body);
+ });
+
test('client.send() GET with non-empty stream', () async {
final request = StreamedRequest('GET', Uri.http(host, ''));
request.headers['Content-Type'] = 'image/png';