Interface StaticFiles.EntityTagResolver
- Enclosing class:
StaticFiles
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionReturns the default weak metadata-based ETag resolver.entityTagFor(@NonNull Path path, @NonNull BasicFileAttributes attributes) Resolves the ETag for the file being served.Returns a strong content-hash ETag resolver.
-
Method Details
-
defaultInstance
Returns the default weak metadata-based ETag resolver.The default resolver produces a weak ETag derived from the file's last-modified epoch second and size. This is deterministic across processes serving the same filesystem. Configure a custom resolver, such as a content-hash resolver, when serving from filesystems that do not preserve modification times, when same-second overwrites are common, or when stronger collision resistance is required.
- Returns:
- the default entity-tag resolver
-
disabledInstance
-
fromContentHash
Returns a strong content-hash ETag resolver.This resolver streams the served file through SHA-256 on the request-handling thread and emits strong ETags with values of the form
sha256-<lowercase-hex>. It does not cache digests and it fully reads the file forHttpMethod.HEADrequests as well asHttpMethod.GETrequests. Applications serving large files or HEAD-heavy traffic should prefer a manifest-backed resolver.- Returns:
- a strong content-hash entity-tag resolver
-
entityTagFor
@NonNull Optional<EntityTag> entityTagFor(@NonNull Path path, @NonNull BasicFileAttributes attributes) Resolves the ETag for the file being served.Implementations must be thread-safe;
StaticFilesinvokes resolvers concurrently from request-handling threads. Resolvers run on the request-handling thread, so expensive work such as content hashing or network calls should be cached or precomputed.- Parameters:
path- the resolved file path being servedattributes- the file attributes read for this response- Returns:
- the ETag to emit, or
Optional.empty()to omit it
-