Browse Source

style(nextcloud): cleaup header map handling

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/592/head
Nikolas Rimikis 1 year ago
parent
commit
d072c91ff1
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 30
      packages/nextcloud/lib/src/webdav/client.dart

30
packages/nextcloud/lib/src/webdav/client.dart

@ -33,8 +33,8 @@ class WebDavClient {
for (final header in {
HttpHeaders.contentTypeHeader: 'application/xml',
...?rootClient.baseHeaders,
if (headers != null) ...headers,
if (rootClient.authentications.isNotEmpty) ...rootClient.authentications.first.headers,
...?headers,
...?rootClient.authentications.firstOrNull?.headers,
}.entries) {
request.headers.add(header.key, header.value);
}
@ -78,24 +78,16 @@ class WebDavClient {
Future<WebDavMultistatus> _parseResponse(final HttpClientResponse response) async =>
WebDavMultistatus.fromXmlElement(xml.XmlDocument.parse(await response.body).rootElement);
Map<String, String>? _getUploadHeaders({
Map<String, String> _getUploadHeaders({
required final DateTime? lastModified,
required final DateTime? created,
required final int? contentLength,
}) {
final headers = <String, String>{
if (lastModified != null) ...{
'X-OC-Mtime': (lastModified.millisecondsSinceEpoch ~/ 1000).toString(),
},
if (created != null) ...{
'X-OC-CTime': (created.millisecondsSinceEpoch ~/ 1000).toString(),
},
if (contentLength != null) ...{
'Content-Length': contentLength.toString(),
},
}) =>
{
if (lastModified != null) 'X-OC-Mtime': (lastModified.millisecondsSinceEpoch ~/ 1000).toString(),
if (created != null) 'X-OC-CTime': (created.millisecondsSinceEpoch ~/ 1000).toString(),
if (contentLength != null) HttpHeaders.contentLengthHeader: contentLength.toString(),
};
return headers.isNotEmpty ? headers : null;
}
/// Gets the WebDAV capabilities of the server.
Future<WebDavOptions> options() async {
@ -253,11 +245,7 @@ class WebDavClient {
.toXmlString(),
) as Uint8List,
),
headers: {
if (depth != null) ...{
'Depth': depth.value,
},
},
headers: depth != null ? {'Depth': depth.value} : null,
),
);

Loading…
Cancel
Save