Package com.linecorp.armeria.server.file
Class FileServiceBuilder
java.lang.Object
com.linecorp.armeria.server.file.FileServiceBuilder
Builds a new
FileService
and its FileServiceConfig
. Use the factory methods in
FileService
if you do not override the default settings.-
Method Summary
Modifier and TypeMethodDescriptionaddHeader
(CharSequence name, Object value) Adds the specified HTTP header.addHeaders
(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) Adds the specified HTTP headers.autoDecompress
(boolean autoDecompress) Sets whether pre-compressed files could be served after being decompressed, when a client does notaccept
a compressed file.autoIndex
(boolean autoIndex) Sets whetherFileService
auto-generates a directory listing for a directory without anindex.html
file.build()
Returns a newly-createdFileService
based on the properties of this builder.cacheControl
(CacheControl cacheControl) Sets the"cache-control"
header.cacheControl
(CharSequence cacheControl) Sets the"cache-control"
header.Sets theClock
that provides the current date and time.entryCacheSpec
(String entryCacheSpec) Sets the Caffeine specification string of the cache that stores the content of theHttpFile
s read by theFileService
.maxCacheEntries
(int maxCacheEntries) Sets the maximum allowed number of cached file entries.maxCacheEntrySizeBytes
(int maxCacheEntrySizeBytes) Sets the maximum allowed size of a cached file entry.mediaTypeResolver
(MediaTypeResolver mediaTypeResolver) Sets theMediaTypeResolver
that determines a file'sMediaType
using its path.serveCompressedFiles
(boolean serveCompressedFiles) Sets whether pre-compressed files should be served.setHeader
(CharSequence name, Object value) Sets the specified HTTP header.setHeaders
(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) Sets the specified HTTP headers.toString()
-
Method Details
-
clock
Sets theClock
that provides the current date and time. -
maxCacheEntries
Sets the maximum allowed number of cached file entries. If not set, up to1024
entries are cached by default. -
entryCacheSpec
Sets the Caffeine specification string of the cache that stores the content of theHttpFile
s read by theFileService
. If not set,Flags.fileServiceCacheSpec()
is used by default. -
serveCompressedFiles
Sets whether pre-compressed files should be served.FileService
supports serving files compressed with gzip, with the extension".gz"
, and brotli, with the extension".br"
. The extension should be appended to the original file. For example, to serveindex.js
either raw, gzip-compressed, or brotli-compressed, there should be three files,index.js
,index.js.gz
, andindex.js.br
. By default, this feature is disabled.Some tools for precompressing resources during a build process include
gulp-zopfli
andgulp-brotli
, which by default create files with the correct extension. -
autoDecompress
Sets whether pre-compressed files could be served after being decompressed, when a client does notaccept
a compressed file. The compressed file will be automatically decompressed depending on the extension of the compressed file. For example, files compressed with gzip should have the extension".gz"
and compressed with brotli should have the extension".br"
.Note that this option is valid only when
serveCompressedFiles(boolean)
is enabled.- See Also:
-
maxCacheEntrySizeBytes
Sets the maximum allowed size of a cached file entry. The file bigger than this value will not be cached. If not set, 65536 is used by default. -
autoIndex
Sets whetherFileService
auto-generates a directory listing for a directory without anindex.html
file. By default, this feature is disabled. Consider the security implications of when enabling this feature. -
addHeader
Adds the specified HTTP header. -
addHeaders
public FileServiceBuilder addHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) Adds the specified HTTP headers. -
setHeader
Sets the specified HTTP header. -
setHeaders
public FileServiceBuilder setHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) Sets the specified HTTP headers. -
cacheControl
Sets the"cache-control"
header. This method is a shortcut for:builder.setHeader(HttpHeaderNames.CACHE_CONTROL, cacheControl);
-
cacheControl
Sets the"cache-control"
header. This method is a shortcut for:builder.setHeader(HttpHeaderNames.CACHE_CONTROL, cacheControl);
-
mediaTypeResolver
Sets theMediaTypeResolver
that determines a file'sMediaType
using its path. If not set,MediaTypeResolver.ofDefault()
is used by default. -
build
Returns a newly-createdFileService
based on the properties of this builder. -
toString
-