From f585947d28f9be7588cd2440cd12642676e9c235 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Mon, 4 Dec 2023 15:34:53 -0800 Subject: [PATCH] Test persistentConnection with large request bodies (#984) --- .../lib/src/request_body_tests.dart | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) 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 fe12dd4646..901f7f7ed5 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 @@ void testRequestBody(Client client) { expect(serverReceivedBody.codeUnits, []); }); + 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';