Skip to content

Commit

Permalink
Test persistentConnection with large request bodies (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan authored Dec 4, 2023
1 parent 7c05dde commit f585947
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkgs/http_client_conformance_tests/lib/src/request_body_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,47 @@ void testRequestBody(Client client) {
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';
Expand Down

0 comments on commit f585947

Please sign in to comment.