Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Fixing multi value headers so they are serialized correctly #20

Merged
merged 4 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dio/lib/src/adapters/io_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class IOHttpClientAdapter implements HttpClientAdapter {

//Set Headers
options.headers.forEach((k, v) {
if (v != null) request.headers.set(k, '$v');
if (v != null) request.headers.set(k, v);
});
} on SocketException catch (e, stackTrace) {
if (!e.message.contains('timed out')) {
Expand Down
16 changes: 16 additions & 0 deletions dio/test/request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ void main() {
assert(ri.method == 'GET');
});

test('#test multi value headers', () async {
Response response = await dio.get(
'/multi-value-header',
options: Options(
headers: {
'x-multi-value-request-header': ['value1', 'value2'],
},
),
);
expect(response.statusCode, 200);
expect(
response.headers.value('x-multi-value-request-header-echo'),
equals('value1, value2'),
);
});

test('#test request with URI', () async {
Response response;

Expand Down
14 changes: 14 additions & 0 deletions dio/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ Future<void> startServer() async {
return;
}

if (path == '/multi-value-header') {
response.headers.contentType = ContentType('application', 'json');
response.headers.add(
'x-multi-value-request-header-echo',
request.headers.value('x-multi-value-request-header').toString(),
);
response
..statusCode = 200
..contentLength = -1
..write('');
response.close();
return;
}

if (path == '/download') {
const content = 'I am a text file';
response.headers.set('content-encoding', 'plain');
Expand Down