Browse Source

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

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/1160/head
Nikolas Rimikis 1 year ago
parent
commit
8a5ea4ff20
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 5
      packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart
  2. 10
      packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart
  3. 7
      packages/nextcloud/lib/src/webdav/client.dart

5
packages/dynamite/dynamite_runtime/lib/src/dynamite_client.dart

@ -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);
}

10
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<String, String> headers) {
for (final header in headers.entries) {
add(header.key, header.value);
}
}
}

7
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);

Loading…
Cancel
Save