Class StaticFileHandler

java.lang.Object
io.fluxzero.sdk.web.StaticFileHandler
All Implemented Interfaces:
Closeable, AutoCloseable

public class StaticFileHandler extends Object implements Closeable
Serves static resources with streamed bodies and content-based validators for the selected representation. ETags are SHA-256 digests. Digests of immutable resources in JAR files opened by this handler are reused for that open archive's lifetime, separately for each encoded representation. Other sources, including filesystem overrides, exploded classpaths and externally resolved nested JARs, are read with bounded memory on every request. This detects changed files even when size and modification time are preserved. Keep archives immutable while open and other files stable until pending responses finish; prefer immutable, versioned asset paths.
  • Field Details

  • Constructor Details

    • StaticFileHandler

      public StaticFileHandler()
    • StaticFileHandler

      public StaticFileHandler(String webRoot)
    • StaticFileHandler

      public StaticFileHandler(String webRoot, String resourceBasePath)
    • StaticFileHandler

      public StaticFileHandler(String webRoot, String resourceBasePath, @Nullable String fallbackFile)
    • StaticFileHandler

      public StaticFileHandler(String webRoot, String resourceBasePath, @Nullable String fallbackFile, Set<String> immutableCandidateExtensions)
    • StaticFileHandler

      public StaticFileHandler(String webRoot, String resourceBasePath, @Nullable String fallbackFile, Set<String> ignorePaths, Set<String> immutableCandidateExtensions, long maxAgeSeconds)
    • StaticFileHandler

      public StaticFileHandler(String webRoot, String resourceBasePath, @Nullable String fallbackFile, Set<String> ignorePaths, Set<String> immutableCandidateExtensions, long maxAgeSeconds, boolean cleanUrls)
    • StaticFileHandler

      public StaticFileHandler(@NonNull @NonNull String webRoot, @Nullable Path fsBaseDirectory, @Nullable URI resourceBaseUri, @Nullable String fallbackFile, Set<String> ignorePaths, Set<String> immutableCandidateExtensions, long maxAgeSeconds)
    • StaticFileHandler

      public StaticFileHandler(@NonNull @NonNull String webRoot, @Nullable Path fsBaseDirectory, @Nullable URI resourceBaseUri, @Nullable String fallbackFile, Set<String> ignorePaths, Set<String> immutableCandidateExtensions, long maxAgeSeconds, boolean cleanUrls)
  • Method Details

    • forTargetClass

      public static List<StaticFileHandler> forTargetClass(Class<?> targetClass)
      Creates static-file handlers from the class or package's ServeStatic configuration, resolving relative web paths against the handler path; returns an empty list if no configuration exists.
    • isHandler

      public static boolean isHandler(Class<?> targetClass)
      Returns whether the class or its package hierarchy carries ServeStatic configuration.
    • serveStaticFile

      @HandleGet({"/{filePath:.+}*","","/"}) protected WebResponse serveStaticFile(String filePath, WebRequest request)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable