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

Commit

Permalink
Fixing multi value headers so they are serialized correctly (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: Bradley Hart <[email protected]>
  • Loading branch information
AlexV525 and bradtalabat authored Nov 8, 2022
1 parent 4f1a2f8 commit 9f4e29d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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

0 comments on commit 9f4e29d

Please sign in to comment.