Skip to content

Commit 5efdf2f

Browse files
committed
refactor(nextcloud)!: Mark WebDAV contentLength parameters as required
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 369cd96 commit 5efdf2f

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

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

+5-12
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,14 @@ class WebDavClient {
142142

143143
/// Request to put a new file at [path] with [localData] as content.
144144
///
145-
/// Setting [contentLength] is important because some web servers will consider the file to be empty otherwise.
146-
/// It will be required in the next major release.
147-
///
148145
/// See:
149146
/// * [putStream] for a complete operation executing this request.
150147
http.BaseRequest putStream_Request(
151148
Stream<List<int>> localData,
152149
PathUri path, {
150+
required int contentLength,
153151
DateTime? lastModified,
154152
DateTime? created,
155-
int? contentLength,
156153
void Function(double progress)? onProgress,
157154
}) {
158155
final request = http.StreamedRequest('PUT', _constructUri(path));
@@ -165,7 +162,7 @@ class WebDavClient {
165162
contentLength: contentLength,
166163
);
167164

168-
if (contentLength != null && onProgress != null) {
165+
if (onProgress != null) {
169166
var uploaded = 0;
170167

171168
unawaited(
@@ -190,18 +187,16 @@ class WebDavClient {
190187
/// [created] sets the date when the file was created on the server.
191188
/// [contentLength] sets the length of the [localData] that is uploaded.
192189
/// [onProgress] can be used to watch the upload progress. Possible values range from 0.0 to 1.0. [contentLength] needs to be set for it to work.
193-
/// Setting [contentLength] is important because some web servers will consider the file to be empty otherwise.
194-
/// It will be required in the next major release.
195190
///
196191
/// See:
197192
/// * http://www.webdav.org/specs/rfc2518.html#METHOD_PUT for more information.
198193
/// * [putStream_Request] for the request sent by this method.
199194
Future<http.StreamedResponse> putStream(
200195
Stream<List<int>> localData,
201196
PathUri path, {
197+
required int contentLength,
202198
DateTime? lastModified,
203199
DateTime? created,
204-
int? contentLength,
205200
void Function(double progress)? onProgress,
206201
}) {
207202
final request = putStream_Request(
@@ -575,19 +570,17 @@ class WebDavClient {
575570

576571
static void _addUploadHeaders(
577572
http.BaseRequest request, {
573+
required int contentLength,
578574
DateTime? lastModified,
579575
DateTime? created,
580-
int? contentLength,
581576
}) {
582577
if (lastModified != null) {
583578
request.headers['X-OC-Mtime'] = lastModified.secondsSinceEpoch.toString();
584579
}
585580
if (created != null) {
586581
request.headers['X-OC-CTime'] = created.secondsSinceEpoch.toString();
587582
}
588-
if (contentLength != null) {
589-
request.headers['content-length'] = contentLength.toString();
590-
}
583+
request.headers['content-length'] = contentLength.toString();
591584
}
592585

593586
void _addCopyHeaders(http.BaseRequest request, {required PathUri destinationPath, required bool overwrite}) {

0 commit comments

Comments
 (0)