diff --git a/packages/dynamite/dynamite_runtime/lib/src/client/client.dart b/packages/dynamite/dynamite_runtime/lib/src/client/client.dart index 5207627fc4c..862ffcd0ad6 100644 --- a/packages/dynamite/dynamite_runtime/lib/src/client/client.dart +++ b/packages/dynamite/dynamite_runtime/lib/src/client/client.dart @@ -62,7 +62,22 @@ class DynamiteClient with http.BaseClient { if (cookieJar != null) { final cookies = await cookieJar!.loadForRequest(request.url); if (cookies.isNotEmpty) { - request.headers['cookie'] = cookies.join('; '); + final buffer = StringBuffer(); + + for (final entry in cookies.indexed) { + final cookie = entry.$2; + + buffer + ..write(cookie.name) + ..write('=') + ..write(cookie.value); + + if (entry.$1 < cookies.length - 1) { + buffer.write('; '); + } + } + + request.headers['cookie'] = buffer.toString(); } } diff --git a/packages/dynamite/dynamite_runtime/test/client_test.dart b/packages/dynamite/dynamite_runtime/test/client_test.dart index f563cc7ced5..b16c9e72668 100644 --- a/packages/dynamite/dynamite_runtime/test/client_test.dart +++ b/packages/dynamite/dynamite_runtime/test/client_test.dart @@ -15,7 +15,7 @@ void main() { test('Cookies', () async { final mockedClient = MockClient((request) async { - expect(request.headers['cookie'], equals(Cookie('a', 'b').toString())); + expect(request.headers['cookie'], equals('a=b; a2=b2; a3=b3')); return Response( '', @@ -32,15 +32,19 @@ void main() { cookieJar: cookieJar, ); - await cookieJar.saveFromResponse(uri, [Cookie('a', 'b')]); + await cookieJar.saveFromResponse(uri, [ + Cookie('a', 'b'), + Cookie('a2', 'b2'), + Cookie('a3', 'b3'), + ]); await client.get(uri); final cookies = await cookieJar.loadForRequest(uri); - expect(cookies, hasLength(2)); + expect(cookies, hasLength(4)); expect(cookies[0].name, 'a'); expect(cookies[0].value, 'b'); - expect(cookies[1].name, 'c'); - expect(cookies[1].value, 'd'); + expect(cookies.last.name, 'c'); + expect(cookies.last.value, 'd'); }); test('No cookies', () async {