Skip to content

Answer 405 instead of 412 to a failing precondition on an unsupported method (#1752) - #1755

Merged
thboileau-git merged 1 commit into
2.7from
fix/1752-405-before-412-2.7
Nov 29, 2026
Merged

thboileau-git merged 1 commit into
2.7from
fix/1752-405-before-412-2.7

Conversation

@thboileau-git

@thboileau-git thboileau-git commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1752

RFC 9110 section 13.2.1: a server ignores the preconditions when the response without them would be neither a success nor a 412, and the failures that do not depend on them take precedence. ServerResource evaluated the preconditions first, so a conditional PUT, DELETE, POST or PATCH to a resource that does not support the method got a 412 (or the 428 of the documented recipe) instead of a 405. A client that re-reads and retries on 412 looped on a write that could never succeed.

  • The evaluation is unchanged. When it yields an error status and the resource declares its supported methods (updateAllowedMethods(), the annotated methods by default) without the method of the request, the answer is now 405 with the Allow header.
  • A resource that declares nothing (for example one that overrides put() without annotating it) is not changed: the framework does not guess at overridden methods. Such a resource can override updateAllowedMethods() to declare them (said in the Javadoc of updateAllowedMethods and getPreconditionStatus).
  • A wrong or incomplete declaration can only replace one refusal by another, never skip a precondition. The success and 304 paths are untouched. The allowed methods of the response are saved and restored, so a 412 does not gain an Allow header.
  • No new API. Related finding, not fixed here: A write-only ServerResource (put() without get()) answers 405 to a conditional PUT #1753 (a write-only resource answers 405 to a conditional PUT because the validators come from get()).
  • Tests: ServerResourceMethodNotAllowedTestCase (unit, with guards) and the wire-level MethodNotAllowedWireTestCase.

Same fix on the other maintained versions: 3.0: #1754, 2.6: #1756

🤖 Generated with Claude Code

… method (#1752)

RFC 9110 section 13.2.1: a server ignores the preconditions when the
response without them would be neither a success nor a 412, and the
failures that do not depend on them take precedence. ServerResource
evaluated the preconditions first, so a conditional PUT, DELETE, POST or
PATCH to a resource that does not support the method got a 412 (or the 428
of the documented recipe) instead of a 405, and a client re-reading and
retrying looped on a write that could never succeed.

When the preconditions yield an error and the resource declares its
supported methods (updateAllowedMethods(), the annotated methods by
default) without the method of the request, the answer is now 405 with the
Allow header. A resource that declares nothing, such as one that overrides
the methods without annotating them, is not changed: the framework does
not guess at overridden methods. The evaluation is unchanged otherwise, so
a wrong declaration can never skip a precondition.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

@thboileau-git
thboileau-git merged commit 411a608 into 2.7 Nov 29, 2026
6 checks passed
@thboileau-git
thboileau-git deleted the fix/1752-405-before-412-2.7 branch November 29, 2026 15:08
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.

ServerResource answers 412 (or 428) instead of 405 to a conditional write the resource does not support

1 participant