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

Http2 adatper header support dynamic #2043

Merged
merged 8 commits into from
Nov 27, 2023
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
1 change: 1 addition & 0 deletions plugins/http2_adapter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Support non-TLS connection requests.
- Improve the implementation of `receiveTimeout`.
- Add more header value types implicit support.

## 2.3.2

Expand Down
19 changes: 11 additions & 8 deletions plugins/http2_adapter/lib/src/http2_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Passer-by marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
25 changes: 25 additions & 0 deletions plugins/http2_adapter/test/http2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}