diff --git a/dio/lib/src/adapters/io_adapter.dart b/dio/lib/src/adapters/io_adapter.dart index 430391075..23523a916 100644 --- a/dio/lib/src/adapters/io_adapter.dart +++ b/dio/lib/src/adapters/io_adapter.dart @@ -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')) { diff --git a/dio/test/request_test.dart b/dio/test/request_test.dart index d90881d17..5423edc92 100644 --- a/dio/test/request_test.dart +++ b/dio/test/request_test.dart @@ -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; diff --git a/dio/test/utils.dart b/dio/test/utils.dart index 3d6f6cc32..1ea2313e5 100644 --- a/dio/test/utils.dart +++ b/dio/test/utils.dart @@ -74,6 +74,17 @@ Future 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');