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, final Set<int>? validStatuses,
) async { ) async {
final request = await httpClient.openUrl(method, uri); final request = await httpClient.openUrl(method, uri);
for (final header in headers.entries) { request.headers.addAll(headers);
request.headers.add(header.key, header.value);
}
if (body != null) { if (body != null) {
request.add(body); request.add(body);
} }

10
packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart

@ -41,3 +41,13 @@ extension HttpClientResponseExtension on HttpClientResponse {
return responseHeaders; 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) final request = await rootClient.httpClient.openUrl(method, url)
..persistentConnection = true; ..persistentConnection = true;
for (final header in {
request.headers.addAll({
HttpHeaders.contentTypeHeader: 'application/xml', HttpHeaders.contentTypeHeader: 'application/xml',
...?rootClient.baseHeaders, ...?rootClient.baseHeaders,
...?headers, ...?headers,
...?rootClient.authentications.firstOrNull?.headers, ...?rootClient.authentications.firstOrNull?.headers,
}.entries) { });
request.headers.add(header.key, header.value);
}
if (data != null) { if (data != null) {
request.add(data); request.add(data);

Loading…
Cancel
Save