diff --git a/lib/src/client.dart b/lib/src/client.dart index 56cf7d9..3583010 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -48,9 +48,10 @@ class Client { this.c.options.receiveTimeout = Duration(milliseconds: timeout); /// Test whether the service can connect + /// Accepts both 200 OK and 204 No Content status codes as valid responses Future ping([CancelToken? cancelToken]) async { var resp = await c.wdOptions(this, '/', cancelToken: cancelToken); - if (resp.statusCode != 200) { + if (resp.statusCode != 200 && resp.statusCode != 204) { throw newResponseError(resp); } } diff --git a/lib/src/webdav_dio.dart b/lib/src/webdav_dio.dart index 157623c..d2b6c1b 100644 --- a/lib/src/webdav_dio.dart +++ b/lib/src/webdav_dio.dart @@ -163,7 +163,12 @@ class WdDio with DioMixin implements Dio { optionsHandler: (options) => options.headers?['depth'] = '0', cancelToken: cancelToken); } - + // OPTIONS validate + void _validateOptionsResponse(Response response) { + if (response.statusCode == 200 || response.statusCode == 204) { + throw newResponseError(response); + } + } // // quota // Future wdQuota(Client self, String dataStr, // {CancelToken cancelToken}) { @@ -249,9 +254,7 @@ class WdDio with DioMixin implements Dio { }) async { // fix auth error var pResp = await this.wdOptions(self, path, cancelToken: cancelToken); - if (pResp.statusCode != 200) { - throw newResponseError(pResp); - } + this._validateOptionsResponse(pResp); var resp = await this.req( self, @@ -291,9 +294,7 @@ class WdDio with DioMixin implements Dio { }) async { // fix auth error var pResp = await this.wdOptions(self, path, cancelToken: cancelToken); - if (pResp.statusCode != 200) { - throw newResponseError(pResp); - } + this._validateOptionsResponse(pResp); Response resp; @@ -457,9 +458,7 @@ class WdDio with DioMixin implements Dio { }) async { // fix auth error var pResp = await this.wdOptions(self, path, cancelToken: cancelToken); - if (pResp.statusCode != 200) { - throw newResponseError(pResp); - } + this._validateOptionsResponse(pResp); // mkdir await this._createParent(self, path, cancelToken: cancelToken); @@ -492,9 +491,7 @@ class WdDio with DioMixin implements Dio { }) async { // fix auth error var pResp = await this.wdOptions(self, path, cancelToken: cancelToken); - if (pResp.statusCode != 200) { - throw newResponseError(pResp); - } + this._validateOptionsResponse(pResp); // mkdir await this._createParent(self, path, cancelToken: cancelToken);