Skip to content

Refactor status check to uniformly handle Multi-Status responses#171

Open
rfc2822 wants to merge 2 commits into
mainfrom
167-mkcolmkcalendar-207-multi-status-should-be-treated-as-error
Open

Refactor status check to uniformly handle Multi-Status responses#171
rfc2822 wants to merge 2 commits into
mainfrom
167-mkcolmkcalendar-207-multi-status-should-be-treated-as-error

Conversation

@rfc2822
Copy link
Copy Markdown
Member

@rfc2822 rfc2822 commented May 16, 2026

This pull request refactors the checkStatus function to handle Multi-Status responses uniformly across implementations.

Key changes:

  • Introduce multiStatusIsError parameter to replace manual HttpStatusCode.MultiStatus/HTTP_MULTISTATUS checks
  • Use multiStatusIsError = true for mkcol() (fixes MKCOL/MKCALENDAR: 207 Multi-Status should be treated as error #167)
  • Update method signatures in Ktor and OkHttp implementations
  • Simplify error handling logic and remove redundant comments

- Replace manual `HttpStatusCode.MultiStatus`/`HTTP_MULTISTATUS` checks with unified `multiStatusIsError` parameter
- Update `checkStatus` signature in both Ktor and OkHttp implementations
- Remove redundant comments and simplify error handling logic
@rfc2822 rfc2822 linked an issue May 16, 2026 that may be closed by this pull request
@rfc2822 rfc2822 self-assigned this May 16, 2026
@rfc2822 rfc2822 added the refactoring Internal improvement of existing functions label May 16, 2026
@rfc2822 rfc2822 requested a review from Copilot May 16, 2026 09:03
@rfc2822 rfc2822 marked this pull request as ready for review May 16, 2026 09:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors checkStatus in both OkHttp and Ktor DavResource implementations to centralize handling of HTTP 207 (Multi-Status), allowing callers (notably mkCol) to uniformly treat 207 as an error when required (per #167 / RFC guidance).

Changes:

  • Added a multiStatusIsError parameter to checkStatus to optionally treat HTTP 207 as an error.
  • Updated MOVE/COPY/MKCOL/DELETE call sites to pass multiStatusIsError = true where 207 must fail the operation.
  • Simplified method bodies by removing duplicated 207 checks and related inline comments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/main/kotlin/at/bitfire/dav4jvm/okhttp/DavResource.kt Adds multiStatusIsError to checkStatus and routes MOVE/COPY/MKCOL/DELETE through it to throw on 207.
src/main/kotlin/at/bitfire/dav4jvm/ktor/DavResource.kt Mirrors the same checkStatus refactor and updates relevant request methods to treat 207 as error.
Comments suppressed due to low confidence (2)

src/main/kotlin/at/bitfire/dav4jvm/okhttp/DavResource.kt:655

  • Changing checkStatus from checkStatus(response: Response) to checkStatus(response: Response, multiStatusIsError: Boolean = false) is a binary-incompatible change for any external subclasses compiled against the previous protected method signature (and also breaks Java callers/subclasses, because no 1-arg overload exists). Consider keeping a 1-argument overload that delegates to the new method (or using @JvmOverloads) to preserve compatibility while still supporting the new flag.
    protected fun checkStatus(response: Response, multiStatusIsError: Boolean = false) {
        // handle 2xx response codes
        if (response.code / 100 == 2) {
            if (response.code == HTTP_MULTISTATUS && multiStatusIsError)
                throw HttpException(response)

src/main/kotlin/at/bitfire/dav4jvm/ktor/DavResource.kt:566

  • Changing checkStatus to add the multiStatusIsError parameter is a binary-incompatible change for external subclasses compiled against the previous protected signature, and it’s also awkward to call from Java (no 1-arg overload is generated for default params). Consider keeping a 1-argument overload delegating to the new method (or adding @JvmOverloads) to preserve compatibility.
    protected suspend fun checkStatus(response: HttpResponse, multiStatusIsError: Boolean = false) {
        // handle 2xx response codes
        if (response.status.isSuccess()) {
            if (response.status == HttpStatusCode.MultiStatus && multiStatusIsError)
                throw HttpException.fromResponse(response)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/kotlin/at/bitfire/dav4jvm/okhttp/DavResource.kt
Comment thread src/main/kotlin/at/bitfire/dav4jvm/ktor/DavResource.kt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Internal improvement of existing functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MKCOL/MKCALENDAR: 207 Multi-Status should be treated as error

2 participants