Skip to content

Commit 51beb4e

Browse files
authored
fix(http_client_conformance_tests): multipart server (#1292)
1 parent bbfce40 commit 51beb4e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

pkgs/http_client_conformance_tests/lib/src/multipart_server.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,27 @@ void hybridMain(StreamChannel<Object?> channel) async {
2323
server = (await HttpServer.bind('localhost', 0))
2424
..listen((request) async {
2525
request.response.headers.set('Access-Control-Allow-Origin', '*');
26+
request.response
27+
..contentLength = 0
28+
..statusCode = HttpStatus.ok;
29+
2630
if (request.method == 'OPTIONS') {
2731
// Handle a CORS preflight request:
2832
// https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#preflighted_requests
2933
request.response.headers
3034
..set('Access-Control-Allow-Methods', '*')
3135
..set('Access-Control-Allow-Headers', '*');
36+
await request.response.close();
3237
} else {
3338
final headers = <String, List<String>>{};
3439
request.headers.forEach((field, value) {
3540
headers[field] = value;
3641
});
3742
final body =
3843
await const Utf8Decoder().bind(request).fold('', (x, y) => '$x$y');
39-
channel.sink.add((headers, body));
44+
await request.response.close();
45+
channel.sink.add([headers, body]);
4046
}
41-
unawaited(request.response.close());
4247
});
4348

4449
channel.sink.add(server.port);

pkgs/http_client_conformance_tests/lib/src/multipart_tests.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ void testMultipartRequests(Client client,
3434
request.files.add(MultipartFile.fromString('file1', 'Hello World'));
3535

3636
await client.send(request);
37-
final (headers, body) =
38-
await httpServerQueue.next as (Map<String, List<String>>, String);
37+
final serverRequest = await httpServerQueue.next as List;
38+
final headers = (serverRequest[0] as Map).cast<String, List<Object?>>();
39+
final body = serverRequest[1] as String;
3940
expect(headers['content-length']!.single, '${request.contentLength}');
4041
expect(headers['content-type']!.single,
4142
startsWith('multipart/form-data; boundary='));

0 commit comments

Comments
 (0)