Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test large payloads with persistentConnection = true #984

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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