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

feat(dynamite_runtime,nextcloud): add addAll method to HttpHeaders #1160

Merged
merged 1 commit into from
Nov 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,8 @@ class DynamiteClient {
final Set<int>? validStatuses,
) async {
final request = await httpClient.openUrl(method, uri);
for (final header in headers.entries) {
request.headers.add(header.key, header.value);
}
request.headers.addAll(headers);

if (body != null) {
request.add(body);
}
Expand Down
10 changes: 10 additions & 0 deletions packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ extension HttpClientResponseExtension on HttpClientResponse {
return responseHeaders;
}
}

/// Extension for http headers.
extension HttpHeadersExtension on HttpHeaders {
/// Iteratively adds all header values.
void addAll(final Map<String, String> headers) {
for (final header in headers.entries) {
add(header.key, header.value);
}
}
}
7 changes: 3 additions & 4 deletions packages/nextcloud/lib/src/webdav/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ class WebDavClient {

final request = await rootClient.httpClient.openUrl(method, url)
..persistentConnection = true;
for (final header in {

request.headers.addAll({
HttpHeaders.contentTypeHeader: 'application/xml',
...?rootClient.baseHeaders,
...?headers,
...?rootClient.authentications.firstOrNull?.headers,
}.entries) {
request.headers.add(header.key, header.value);
}
});

if (data != null) {
request.add(data);
Expand Down