Browse Source

Merge pull request #1160 from nextcloud/feat/dynamite/add_all_headers_extension

pull/1163/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
cb28c3a8f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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