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.

  • 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 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