Skip to content

Commit

Permalink
fix(http_client_conformance_tests): multipart server (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zekfad authored Aug 28, 2024
1 parent bbfce40 commit 51beb4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,27 @@ void hybridMain(StreamChannel<Object?> 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 = <String, List<String>>{};
request.headers.forEach((field, value) {
headers[field] = value;
});
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, List<String>>, String);
final serverRequest = await httpServerQueue.next as List;
final headers = (serverRequest[0] as Map).cast<String, List<Object?>>();
final body = serverRequest[1] as String;
expect(headers['content-length']!.single, '${request.contentLength}');
expect(headers['content-type']!.single,
startsWith('multipart/form-data; boundary='));
Expand Down

0 comments on commit 51beb4e

Please sign in to comment.