webdav_client icon indicating copy to clipboard operation
webdav_client copied to clipboard

fix: accept 204 No Content status code in ping method

Open Mahoo12138 opened this issue 7 months ago • 0 comments

Fix: Accept 204 status code for OPTIONS request in ping method

Description

Currently, the ping() method only accepts HTTP status code 200 for OPTIONS requests. However, according to HTTP/1.1 specification, status code 204 (No Content) is also a valid response for OPTIONS requests. This change makes the client more compatible with standard-compliant WebDAV servers.

Changes

  • Modified ping() method to accept both 200 and 204 status codes
  • Added documentation comment explaining the accepted status codes

Code Changes

/// Test whether the service can connect
/// Accepts both 200 OK and 204 No Content status codes as valid responses
Future<void> ping([CancelToken? cancelToken]) async {
  var resp = await c.wdOptions(this, '/', cancelToken: cancelToken);
  if (resp.statusCode != 200 && resp.statusCode != 204) {
    throw newResponseError(resp);
  }
}

Why

  • HTTP/1.1 specification allows both 200 and 204 status codes for OPTIONS requests
  • Some WebDAV servers (like Nginx) correctly return 204 for OPTIONS requests
  • Current implementation unnecessarily restricts compatibility with standard-compliant servers

Testing

  • Tested with Nginx WebDAV server (returns 204)
  • Tested with other WebDAV servers (returns 200)
  • Both cases now work correctly

Mahoo12138 avatar Jun 07 '25 12:06 Mahoo12138