From 51beb4e8a9652499f8a632c86c81679050caae1f Mon Sep 17 00:00:00 2001 From: Yaroslav Vorobev Date: Wed, 28 Aug 2024 20:18:08 +0300 Subject: [PATCH] fix(http_client_conformance_tests): multipart server (#1292) --- .../lib/src/multipart_server.dart | 9 +++++++-- .../lib/src/multipart_tests.dart | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkgs/http_client_conformance_tests/lib/src/multipart_server.dart b/pkgs/http_client_conformance_tests/lib/src/multipart_server.dart index 90e4d8b1a7..3072090dec 100644 --- a/pkgs/http_client_conformance_tests/lib/src/multipart_server.dart +++ b/pkgs/http_client_conformance_tests/lib/src/multipart_server.dart @@ -23,12 +23,17 @@ void hybridMain(StreamChannel channel) async { server = (await HttpServer.bind('localhost', 0)) ..listen((request) async { request.response.headers.set('Access-Control-Allow-Origin', '*'); + request.response + ..contentLength = 0 + ..statusCode = HttpStatus.ok; + if (request.method == 'OPTIONS') { // Handle a CORS preflight request: // https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#preflighted_requests request.response.headers ..set('Access-Control-Allow-Methods', '*') ..set('Access-Control-Allow-Headers', '*'); + await request.response.close(); } else { final headers = >{}; request.headers.forEach((field, value) { @@ -36,9 +41,9 @@ void hybridMain(StreamChannel channel) async { }); final body = await const Utf8Decoder().bind(request).fold('', (x, y) => '$x$y'); - channel.sink.add((headers, body)); + await request.response.close(); + channel.sink.add([headers, body]); } - unawaited(request.response.close()); }); channel.sink.add(server.port); diff --git a/pkgs/http_client_conformance_tests/lib/src/multipart_tests.dart b/pkgs/http_client_conformance_tests/lib/src/multipart_tests.dart index c9ecd90f82..0277e30935 100644 --- a/pkgs/http_client_conformance_tests/lib/src/multipart_tests.dart +++ b/pkgs/http_client_conformance_tests/lib/src/multipart_tests.dart @@ -34,8 +34,9 @@ void testMultipartRequests(Client client, request.files.add(MultipartFile.fromString('file1', 'Hello World')); await client.send(request); - final (headers, body) = - await httpServerQueue.next as (Map>, String); + final serverRequest = await httpServerQueue.next as List; + final headers = (serverRequest[0] as Map).cast>(); + final body = serverRequest[1] as String; expect(headers['content-length']!.single, '${request.contentLength}'); expect(headers['content-type']!.single, startsWith('multipart/form-data; boundary='));