Skip to content

Support conditional entity writing on client-side #100

Done

Description

Activity

  1. ghost assigned on Mar 7, 2012
  2. modified the milestone: Unplanned on Nov 2, 2014
  3. modified the milestone: Unplanned on Dec 27, 2019
  4. thboileau-git commented on Nov 25, 2026

    @thboileau-git
    Collaborator

    Implemented and merged in the three maintained versions (3.0: #1695, 2.7: #1696, 2.6: #1697).

    ClientResource now has per-call conditional writes, so a client can update or delete a resource only if it did not change since it was read, and create it only if it does not exist:

    • Conditions.unchangedSince(Response) builds If-Match from the strong entity tag that was read. Without one, it builds If-Unmodified-Since, but only if the modification date can be deduced to be strong (response Date at least one second after Last-Modified, RFC 9110 §8.8.2.2). Otherwise it throws IllegalArgumentException, so an unconditional write is never sent by accident.
    • Conditions.ifAbsent() builds If-None-Match: * (create only).
    • ClientResource.put(...), patch(...) (entity as Representation or Object) and delete(...) have overloads taking a Conditions. The conditions apply to that call only, nothing sticks to the resource, and the call is never retried automatically. A failed condition is a 412 ResourceException.

    An automatic mode (conditions added without being asked) was deliberately not added.

    Related: #1694 (Tag(String) creates a weak tag, which never matches If-Match).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions