Class StaticFiles.Builder

java.lang.Object
com.jsgalactic.axiom.http.StaticFiles.Builder
Enclosing class:
StaticFiles

public static final class StaticFiles.Builder extends Object
Collects the immutable handler's configuration. Not shared until build().
  • Method Details

    • capture

      public StaticFiles.Builder capture(String name)
      Sets the wildcard capture that holds the file path, path by default.
      Parameters:
      name - capture name declared by the route template
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the name is not a capture identifier
    • maxFileSize

      public StaticFiles.Builder maxFileSize(long bytes)
      Sets the largest file this handler will serve, 64 MiB by default.
      Parameters:
      bytes - maximum representation length, positive and at most 1 TiB
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the bound is outside that range
    • cacheControl

      public StaticFiles.Builder cacheControl(String value)
      Sets the Cache-Control field sent with every file.
      Parameters:
      value - header value of 1 to 512 visible ASCII characters
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the value is empty, overlong or contains a control
    • contentType

      public StaticFiles.Builder contentType(String extension, String contentType)
      Adds or replaces the content type of one lowercase extension. Overrides take precedence over the built-in table; extensions without an entry use StaticFiles.DEFAULT_CONTENT_TYPE.
      Parameters:
      extension - file extension without the dot, 1 to 16 ASCII letters or digits
      contentType - exact media type with optional parameters
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the extension or content type is invalid
    • build

      public Handler build()
      Builds the handler. The result holds no reference to this builder and may be shared.
      Returns:
      immutable handler for GET and HEAD requests