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.

Resolves ETag values for static-file responses.
Author:
Mark Allen
  • 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

      Returns a resolver that omits ETag.
      Returns:
      the disabled entity-tag resolver
    • 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>. When used by StaticFiles, it hashes a channel acquired under the helper's root and file checks. It does not cache digests and it fully reads the file for HttpMethod.HEAD requests as well as HttpMethod.GET requests. Applications serving large files or HEAD-heavy traffic should prefer a manifest-backed resolver.

      Returns:
      a strong content-hash entity-tag resolver
    • entityTagFor

      Resolves the ETag for the file being served.

      Implementations must be thread-safe; StaticFiles invokes 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 served
      attributes - the file attributes read for this response
      Returns:
      the ETag to emit, or Optional.empty() to omit it