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. 41
      packages/nextcloud/lib/src/webdav/client.dart

41
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,33 +195,27 @@ 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(
'PROPFIND', await _send(
_constructPath(path), 'PROPFIND',
[207, 301], _constructPath(path),
data: Stream.value( [207],
Uint8List.fromList( data: Stream.value(
utf8.encode( Uint8List.fromList(
WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()).toXmlElement(namespaces: namespaces).toXmlString(), utf8.encode(
WebDavPropfind(prop: prop ?? WebDavPropWithoutValues())
.toXmlElement(namespaces: namespaces)
.toXmlString(),
),
), ),
), ),
), headers: {
headers: { if (depth != null) ...{
if (depth != null) ...{ '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