DATAREST-1036-ruthes00. Added support for If-None-Match: * with PUT requests - #2592
Open
ruthst00 wants to merge 2 commits into
Open
DATAREST-1036-ruthes00. Added support for If-None-Match: * with PUT requests#2592ruthst00 wants to merge 2 commits into
If-None-Match: * with PUT requests#2592ruthst00 wants to merge 2 commits into
Conversation
… 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>
…header. Signed-off-by: ruthes00 <ruthes00@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: — AddedWILDCARD_ETAGconstant (representing*) and a newverifyNoneMatch(PersistentEntity, Object)method that throwsETagDoesntMatchExceptionwhen the ETag is a wildcard and the target resource already exists.RepositoryEntityController.java: — Added a@RequestHeader HttpHeaders requestHeadersparameter toputItemResource. WhenIf-None-Match: *is present, the handler looks up the existing resource by ID and callsETag.WILDCARD_ETAG.verifyNoneMatch(...)— if the resource exists, a412 Precondition Failedis returned (via the existingETagDoesntMatchExceptionhandler); 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_ETAGnever rejects, andETag.from("*")equalsWILDCARD_ETAG.RepositoryEntityControllerIntegrationTests.java: — Updated all existingputItemResourcecalls to pass the newHttpHeadersparameter, and added 2 new integration tests: one verifying a PUT withIf-None-Match: *succeeds (201) when the resource doesn't exist, and one verifying it fails withETagDoesntMatchExceptionwhen the resource already exists.etags-and-other-conditionals.adoc: — Added a newIf-None-Match: *with PUT subsection explaining the create-only guard semantics with a curl example.