Skip to content

Conversation

@Mahoo12138
Copy link

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

- 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
@Mahoo12138 Mahoo12138 force-pushed the fix/ping-accept-204 branch from e46d6ba to 7b43ba2 Compare June 7, 2025 12:45
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant