Browse Source

refactor(nextcloud): Follow WebDAV redirects automatically

pull/520/head
jld3103 1 year ago
parent
commit
69ba5e61ef
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 21
      packages/nextcloud/lib/src/webdav/client.dart

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

@ -29,7 +29,6 @@ class WebDavClient {
method, method,
Uri.parse(url), Uri.parse(url),
) )
..followRedirects = false
..persistentConnection = true; ..persistentConnection = true;
for (final header in { for (final header in {
HttpHeaders.contentTypeHeader: 'application/xml', HttpHeaders.contentTypeHeader: 'application/xml',
@ -196,14 +195,17 @@ class WebDavClient {
final String? depth, final String? depth,
}) async { }) async {
assert(depth == null || ['0', '1', 'infinity'].contains(depth), 'Depth has to be 0, 1 or infinity'); assert(depth == null || ['0', '1', 'infinity'].contains(depth), 'Depth has to be 0, 1 or infinity');
final response = await _send( return _parseResponse(
await _send(
'PROPFIND', 'PROPFIND',
_constructPath(path), _constructPath(path),
[207, 301], [207],
data: Stream.value( data: Stream.value(
Uint8List.fromList( Uint8List.fromList(
utf8.encode( utf8.encode(
WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()).toXmlElement(namespaces: namespaces).toXmlString(), WebDavPropfind(prop: prop ?? WebDavPropWithoutValues())
.toXmlElement(namespaces: namespaces)
.toXmlString(),
), ),
), ),
), ),
@ -212,17 +214,8 @@ class WebDavClient {
'Depth': depth, '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]. /// Runs the filter-files report with the [filterRules] on the resource at [path].

Loading…
Cancel
Save