Skip to content

Commit

Permalink
feat(dynamite_runtime,nextcloud): add addAll method to HttpHeaders
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
  • Loading branch information
Leptopoda committed Nov 19, 2023
1 parent c5f54ea commit 8a5ea4f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
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

0 comments on commit 8a5ea4f

Please sign in to comment.