diff --git a/plugins/http2_adapter/CHANGELOG.md b/plugins/http2_adapter/CHANGELOG.md index 1b6622feb..1cb60f918 100644 --- a/plugins/http2_adapter/CHANGELOG.md +++ b/plugins/http2_adapter/CHANGELOG.md @@ -4,6 +4,7 @@ - Support non-TLS connection requests. - Improve the implementation of `receiveTimeout`. +- Add more header value types implicit support. ## 2.3.2 diff --git a/plugins/http2_adapter/lib/src/http2_adapter.dart b/plugins/http2_adapter/lib/src/http2_adapter.dart index b27b84745..a8eff0bcf 100644 --- a/plugins/http2_adapter/lib/src/http2_adapter.dart +++ b/plugins/http2_adapter/lib/src/http2_adapter.dart @@ -62,14 +62,17 @@ class Http2Adapter implements HttpClientAdapter { // Add custom headers headers.addAll( - options.headers.keys - .map( - (key) => Header.ascii( - key.toLowerCase(), - options.headers[key] as String? ?? '', - ), - ) - .toList(), + options.headers.entries.map( + (entry) { + final String v; + if (entry.value is Iterable) { + v = entry.value.join(', '); + } else { + v = '${entry.value}'; + } + return Header.ascii(entry.key.toLowerCase(), v); + }, + ).toList(), ); // Creates a new outgoing stream. diff --git a/plugins/http2_adapter/test/http2_test.dart b/plugins/http2_adapter/test/http2_test.dart index 972558317..43a560875 100644 --- a/plugins/http2_adapter/test/http2_test.dart +++ b/plugins/http2_adapter/test/http2_test.dart @@ -133,4 +133,29 @@ void main() { final res = await dio.get('absolute-redirect/2'); expect(res.statusCode, 200); }); + + test('header value types implicit support', () async { + final dio = Dio() + ..options.baseUrl = 'https://httpbun.com/' + ..httpClientAdapter = Http2Adapter(ConnectionManager()); + + final res = await dio.post( + 'post', + data: 'TEST', + options: Options( + headers: { + 'ListKey': ['1', '2'], + 'StringKey': '1', + 'NumKey': 2, + 'BooleanKey': false, + }, + ), + ); + final content = res.data.toString(); + expect(content, contains('TEST')); + expect(content, contains('Listkey: 1, 2')); + expect(content, contains('Stringkey: 1')); + expect(content, contains('Numkey: 2')); + expect(content, contains('Booleankey: false')); + }); }