Class AbstractHttpFileBuilder

java.lang.Object
com.linecorp.armeria.server.file.AbstractHttpFileBuilder
Direct Known Subclasses:
AggregatedHttpFileBuilder, HttpFileBuilder

public abstract class AbstractHttpFileBuilder
extends Object
A skeletal builder class which helps easier implementation of HttpFileBuilder or AggregatedHttpFileBuilder.
  • Constructor Details

    • AbstractHttpFileBuilder

      public AbstractHttpFileBuilder()
  • Method Details

    • clock

      protected final Clock clock()
      Returns the Clock that provides the current date and time.
    • clock

      public AbstractHttpFileBuilder clock​(Clock clock)
      Sets the Clock that provides the current date and time. By default, Clock.systemUTC() is used.
    • isDateEnabled

      protected final boolean isDateEnabled()
      Returns whether to set the "date" header automatically.
    • date

      public AbstractHttpFileBuilder date​(boolean dateEnabled)
      Sets whether to set the "date" header automatically. By default, the "date" header is set automatically.
    • isLastModifiedEnabled

      protected final boolean isLastModifiedEnabled()
      Returns whether to set the "last-modified" header automatically.
    • lastModified

      public AbstractHttpFileBuilder lastModified​(boolean lastModifiedEnabled)
      Sets whether to set the "last-modified" header automatically. By default, the "last-modified" is set automatically.
    • isContentTypeAutoDetectionEnabled

      protected final boolean isContentTypeAutoDetectionEnabled()
      Sets whether to set the "content-type" header automatically based on the extension of the file.
    • autoDetectedContentType

      public AbstractHttpFileBuilder autoDetectedContentType​(boolean contentTypeAutoDetectionEnabled)
      Sets whether to set the "content-type" header automatically based on the extension of the file. By default, the "content-type" header is set automatically.
    • entityTagFunction

      @Nullable protected final BiFunction<String,​HttpFileAttributes,​String> entityTagFunction()
      Returns the function which generates the entity tag that's used for setting the "etag" header automatically.
      Returns:
      the etag function, or null if the "etag" header is not set automatically.
    • entityTag

      public AbstractHttpFileBuilder entityTag​(boolean enabled)
      Sets whether to set the "etag" header automatically based on the path and attributes of the file. By default, the "etag" header is set automatically. Use entityTag(BiFunction) to customize how an entity tag is generated.
    • entityTag

      public AbstractHttpFileBuilder entityTag​(BiFunction<String,​HttpFileAttributes,​String> entityTagFunction)
      Sets the function which generates the entity tag that's used for setting the "etag" header automatically.
      Parameters:
      entityTagFunction - the entity tag function that generates the entity tag, or null to disable setting the "etag" header.
    • buildHeaders

      protected final HttpHeaders buildHeaders()
      Returns the immutable additional HttpHeaders which will be set when building an HttpResponse.
    • addHeader

      public AbstractHttpFileBuilder addHeader​(CharSequence name, Object value)
      Adds the specified HTTP header.
    • addHeaders

      public AbstractHttpFileBuilder addHeaders​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> headers)
      Adds the specified HTTP headers.
    • setHeader

      public AbstractHttpFileBuilder setHeader​(CharSequence name, Object value)
      Sets the specified HTTP header.
    • setHeaders

      public AbstractHttpFileBuilder setHeaders​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> headers)
      Sets the specified HTTP headers.
    • contentType

      public AbstractHttpFileBuilder contentType​(MediaType contentType)
      Sets the "content-type" header. This method is a shortcut for:
      
       builder.autoDetectedContentType(false);
       builder.setHeader(HttpHeaderNames.CONTENT_TYPE, contentType);
       
    • contentType

      public AbstractHttpFileBuilder contentType​(CharSequence contentType)
      Sets the "content-type" header. This method is a shortcut for:
      
       builder.autoDetectedContentType(false);
       builder.setHeader(HttpHeaderNames.CONTENT_TYPE, contentType);
       
    • cacheControl

      public AbstractHttpFileBuilder cacheControl​(CacheControl cacheControl)
      Sets the "cache-control" header. This method is a shortcut for:
      
       builder.setHeader(HttpHeaderNames.CACHE_CONTROL, cacheControl);
       
    • cacheControl

      public AbstractHttpFileBuilder cacheControl​(CharSequence cacheControl)
      Sets the "cache-control" header. This method is a shortcut for:
      
       builder.setHeader(HttpHeaderNames.CACHE_CONTROL, cacheControl);