diff --git a/packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart b/packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart index 4ebb10f0..eb165ca4 100644 --- a/packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart +++ b/packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart @@ -442,9 +442,8 @@ class DynamiteClient { final Set? 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); } diff --git a/packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart b/packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart index 005a80aa..7351e2de 100644 --- a/packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart +++ b/packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart @@ -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 headers) { + for (final header in headers.entries) { + add(header.key, header.value); + } + } +} diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index b9ba4bd0..a41d7fc2 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -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);