Skip to content

DATAREST-1036-ruthes00. Added support for If-None-Match: * with PUT requests - #2592

Open
ruthst00 wants to merge 2 commits into
spring-projects:mainfrom
ruthst00:DATAREST-814-ruthes00
Open

DATAREST-1036-ruthes00. Added support for If-None-Match: * with PUT requests#2592
ruthst00 wants to merge 2 commits into
spring-projects:mainfrom
ruthst00:DATAREST-814-ruthes00

Conversation

@ruthst00

@ruthst00 ruthst00 commented Aug 27, 2026

Copy link
Copy Markdown
  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

Overview

Added support for If-None-Match: * with PUT requests, implementing RFC 7232 §3.2 semantics (create-only guard). The following files were changed:

  • ETag.java: — Added WILDCARD_ETAG constant (representing *) and a new verifyNoneMatch(PersistentEntity, Object) method that throws ETagDoesntMatchException when the ETag is a wildcard and the target resource already exists.

  • RepositoryEntityController.java: — Added a @RequestHeader HttpHeaders requestHeaders parameter to putItemResource. When If-None-Match: * is present, the handler looks up the existing resource by ID and calls ETag.WILDCARD_ETAG.verifyNoneMatch(...) — if the resource exists, a 412 Precondition Failed is returned (via the existing ETagDoesntMatchException handler); if it doesn't exist, the PUT proceeds normally as a creation.

  • ETagUnitTests.java: — Added 4 unit tests covering: wildcard throws when resource exists, wildcard passes when resource is null, NO_ETAG never rejects, and ETag.from("*") equals WILDCARD_ETAG.

  • RepositoryEntityControllerIntegrationTests.java: — Updated all existing putItemResource calls to pass the new HttpHeaders parameter, and added 2 new integration tests: one verifying a PUT with If-None-Match: * succeeds (201) when the resource doesn't exist, and one verifying it fails with ETagDoesntMatchException when the resource already exists.

  • etags-and-other-conditionals.adoc: — Added a new If-None-Match: * with PUT subsection explaining the create-only guard semantics with a curl example.

… requests, implementing RFC 7232 §3.2 semantics (create-only guard). The following files were changed:

__`ETag.java`__ — Added `WILDCARD_ETAG` constant (representing `*`) and a new `verifyNoneMatch(PersistentEntity, Object)` method that throws `ETagDoesntMatchException` when the ETag is a wildcard and the target resource already exists.

__`RepositoryEntityController.java`__ — Added a `@RequestHeader HttpHeaders requestHeaders` parameter to `putItemResource`. When `If-None-Match: *` is present, the handler looks up the existing resource by ID and calls `ETag.WILDCARD_ETAG.verifyNoneMatch(...)` — if the resource exists, a `412 Precondition Failed` is returned (via the existing `ETagDoesntMatchException` handler); if it doesn't exist, the PUT proceeds normally as a creation.

__`ETagUnitTests.java`__ — Added 4 unit tests covering: wildcard throws when resource exists, wildcard passes when resource is null, `NO_ETAG` never rejects, and `ETag.from("*")` equals `WILDCARD_ETAG`.

__`RepositoryEntityControllerIntegrationTests.java`__ — Updated all existing `putItemResource` calls to pass the new `HttpHeaders` parameter, and added 2 new integration tests: one verifying a PUT with `If-None-Match: *` succeeds (201) when the resource doesn't exist, and one verifying it fails with `ETagDoesntMatchException` when the resource already exists.

__`etags-and-other-conditionals.adoc`__ — Added a new `If-None-Match: *` with PUT subsection explaining the create-only guard semantics with a curl example.

Signed-off-by: ruthes00 <ruthes00@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 27, 2026
…header.

Signed-off-by: ruthes00 <ruthes00@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants