diff --git a/packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart b/packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart index e9a436e04dd..1f7f54127f1 100644 --- a/packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart +++ b/packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart @@ -450,7 +450,9 @@ class DynamiteClient { if (cookieJar != null) { final cookies = await cookieJar!.loadForRequest(uri); - request.headers['cookie'] = cookies.join('; '); + if (cookies.isNotEmpty) { + request.headers['cookie'] = cookies.join('; '); + } } final response = await httpClient.send(request); diff --git a/packages/dynamite/dynamite_runtime/test/client_test.dart b/packages/dynamite/dynamite_runtime/test/client_test.dart index 3b8e910f3c2..fe3dd47ad33 100644 --- a/packages/dynamite/dynamite_runtime/test/client_test.dart +++ b/packages/dynamite/dynamite_runtime/test/client_test.dart @@ -40,4 +40,19 @@ void main() { expect(cookies[1].name, 'c'); expect(cookies[1].value, 'd'); }); + + test('No cookies', () async { + final mockedClient = MockClient((request) async { + expect(request.headers['cookie'], isNull); + return Response('', 200); + }); + + final client = DynamiteClient( + uri, + httpClient: mockedClient, + cookieJar: cookieJar, + ); + + await client.executeRequest('GET', '', {}, null, null); + }); }