From 69ba5e61ef2fc5e38baf9cee3670218f29437bf9 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Tue, 1 Aug 2023 22:51:37 +0200 Subject: [PATCH] refactor(nextcloud): Follow WebDAV redirects automatically --- packages/nextcloud/lib/src/webdav/client.dart | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index cbe9b5a6..1f6703e6 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -29,7 +29,6 @@ class WebDavClient { method, Uri.parse(url), ) - ..followRedirects = false ..persistentConnection = true; for (final header in { HttpHeaders.contentTypeHeader: 'application/xml', @@ -196,33 +195,27 @@ class WebDavClient { final String? depth, }) async { assert(depth == null || ['0', '1', 'infinity'].contains(depth), 'Depth has to be 0, 1 or infinity'); - final response = await _send( - 'PROPFIND', - _constructPath(path), - [207, 301], - data: Stream.value( - Uint8List.fromList( - utf8.encode( - WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()).toXmlElement(namespaces: namespaces).toXmlString(), + return _parseResponse( + await _send( + 'PROPFIND', + _constructPath(path), + [207], + data: Stream.value( + Uint8List.fromList( + utf8.encode( + WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()) + .toXmlElement(namespaces: namespaces) + .toXmlString(), + ), ), ), - ), - headers: { - if (depth != null) ...{ - 'Depth': depth, + headers: { + if (depth != null) ...{ + 'Depth': depth, + }, }, - }, + ), ); - if (response.statusCode == 301) { - // coverage:ignore-start - return propfind( - response.headers['location']!.first, - prop: prop, - depth: depth, - ); - // coverage:ignore-end - } - return _parseResponse(response); } /// Runs the filter-files report with the [filterRules] on the resource at [path].