From 7b43ba2911895a26884eba8d28869cc618e3f28c Mon Sep 17 00:00:00 2001 From: Mahoo12138 Date: Sat, 7 Jun 2025 20:45:09 +0800 Subject: [PATCH 1/2] fix: accept 204 No Content status code in ping method - Update the ping method to consider 204 No Content as a valid response - This change improves compatibility with services that may return 204 instead of 200 --- lib/src/client.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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); } } From 830c185c2cdba6f134578e7a5e13bf35a5c386fa Mon Sep 17 00:00:00 2001 From: Mahoo12138 Date: Sat, 7 Jun 2025 20:55:04 +0800 Subject: [PATCH 2/2] refactor: improve OPTIONS request validation - Add a new method _validateOptionsResponse to handle OPTIONS response validation - Update wdProps, wdMkcol, wdMkdir, and wdTouch methods to use the new validation method - Improve error handling by throwing a more descriptive error when OPTIONS request fails --- lib/src/webdav_dio.dart | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) 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);