Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing multi value headers so they are serialized correctly #1586

Closed
wants to merge 2 commits into from
Closed
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 @@ -54,7 +54,7 @@ class DefaultHttpClientAdapter 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) {
if (e.message.contains('timed out')) {
Expand Down
10 changes: 10 additions & 0 deletions dio/test/request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ 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
11 changes: 11 additions & 0 deletions dio/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ 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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use single quotes here like this:

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