Class ConditionalRequests
This helper supports cache validation and optimistic concurrency for application responses without forcing resource
methods into MarshaledResponse. Applications still own representation validators: choose the current
EntityTag, Last-Modified instant, cache headers, and normal success response.
When a request precondition requires an immediate response, responseFor(Request, EntityTag, Instant)
returns a bodyless Response with status 304 Not Modified or 412 Precondition Failed.
Otherwise it returns Optional.empty() and the application should build its normal response.
Malformed entity-tag preconditions fail closed when they protect writes: malformed If-Match returns
412 Precondition Failed, and malformed If-None-Match does the same for non-GET/HEAD
requests. Malformed If-None-Match on GET and HEAD is treated as a cache miss.
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionresponseFor(@NonNull Request request, @Nullable EntityTag entityTag, @Nullable Instant lastModified) Evaluates conditional request headers against the supplied validators.responseFor(@NonNull Request request, @Nullable EntityTag entityTag, @Nullable Instant lastModified, @Nullable Map<@NonNull String, @NonNull Set<@NonNull String>> extraHeaders) Evaluates conditional request headers against the supplied validators.validatorHeaders(@Nullable EntityTag entityTag, @Nullable Instant lastModified) Builds validator headers for the supplied representation validators.validatorHeaders(@Nullable EntityTag entityTag, @Nullable Instant lastModified, @Nullable Map<@NonNull String, @NonNull Set<@NonNull String>> extraHeaders) Builds validator headers plus endpoint-specific metadata headers.
-
Method Details
-
responseFor
public static @NonNull Optional<Response> responseFor(@NonNull Request request, @Nullable EntityTag entityTag, @Nullable Instant lastModified) Evaluates conditional request headers against the supplied validators.- Parameters:
request- the request whose conditional headers should be evaluatedentityTag- the current representation's entity tag, ornullif unavailablelastModified- the current representation's last-modified instant, ornullif unavailable- Returns:
- a short-circuit response, or
Optional.empty()when the application should continue normally
-
responseFor
public static @NonNull Optional<Response> responseFor(@NonNull Request request, @Nullable EntityTag entityTag, @Nullable Instant lastModified, @Nullable Map<@NonNull String, @NonNull Set<@NonNull String>> extraHeaders) Evaluates conditional request headers against the supplied validators.extraHeadersare included on short-circuit304and412responses. They are intended for response metadata such asCache-ControlorVary; validator and body-framing headers are rejected because they are controlled by this helper.- Parameters:
request- the request whose conditional headers should be evaluatedentityTag- the current representation's entity tag, ornullif unavailablelastModified- the current representation's last-modified instant, ornullif unavailableextraHeaders- endpoint-specific metadata headers to include on short-circuit responses- Returns:
- a short-circuit response, or
Optional.empty()when the application should continue normally
-
validatorHeaders
public static @NonNull Map<@NonNull String, @NonNull Set<@NonNull String>> validatorHeaders(@Nullable EntityTag entityTag, @Nullable Instant lastModified) Builds validator headers for the supplied representation validators.- Parameters:
entityTag- the current representation's entity tag, ornullif unavailablelastModified- the current representation's last-modified instant, ornullif unavailable- Returns:
- immutable
ETagandLast-Modifiedheaders for the supplied validators
-
validatorHeaders
public static @NonNull Map<@NonNull String, @NonNull Set<@NonNull String>> validatorHeaders(@Nullable EntityTag entityTag, @Nullable Instant lastModified, @Nullable Map<@NonNull String, @NonNull Set<@NonNull String>> extraHeaders) Builds validator headers plus endpoint-specific metadata headers.extraHeadersare intended for response metadata such asCache-ControlorVary; validator and body-framing headers are rejected because they are controlled by this helper.- Parameters:
entityTag- the current representation's entity tag, ornullif unavailablelastModified- the current representation's last-modified instant, ornullif unavailableextraHeaders- endpoint-specific metadata headers to include with the validators- Returns:
- immutable combined headers
-