Package com.linecorp.armeria.server.file
Class AbstractHttpFileBuilder
java.lang.Object
com.linecorp.armeria.server.file.AbstractHttpFileBuilder
- Direct Known Subclasses:
AggregatedHttpFileBuilder
,HttpFileBuilder
A skeletal builder class which helps easier implementation of
HttpFileBuilder
or
AggregatedHttpFileBuilder
.-
Constructor Summary
-
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.autoDetectedContentType
(boolean contentTypeAutoDetectionEnabled) Sets whether to set the"content-type"
header automatically based on the extension of the file.protected final HttpHeaders
Returns the immutable additionalHttpHeaders
which will be set when building anHttpResponse
.cacheControl
(CacheControl cacheControl) Sets the"cache-control"
header.cacheControl
(CharSequence cacheControl) Sets the"cache-control"
header.protected final Clock
clock()
Returns theClock
that provides the current date and time.Sets theClock
that provides the current date and time.contentType
(MediaType contentType) Sets the"content-type"
header.contentType
(CharSequence contentType) Sets the"content-type"
header.date
(boolean dateEnabled) Sets whether to set the"date"
header automatically.entityTag
(boolean enabled) Sets whether to set the"etag"
header automatically based on the path and attributes of the file.entityTag
(BiFunction<String, HttpFileAttributes, String> entityTagFunction) Sets the function which generates the entity tag that's used for setting the"etag"
header automatically.protected final @Nullable BiFunction<String,
HttpFileAttributes, String> Returns the function which generates the entity tag that's used for setting the"etag"
header automatically.protected final boolean
Sets whether to set the"content-type"
header automatically based on the extension of the file.protected final boolean
Returns whether to set the"date"
header automatically.protected final boolean
Returns whether to set the"last-modified"
header automatically.lastModified
(boolean lastModifiedEnabled) Sets whether to set the"last-modified"
header automatically.setHeader
(CharSequence name, Object value) Sets the specified HTTP header.setHeaders
(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) Sets the specified HTTP headers.
-
Constructor Details
-
AbstractHttpFileBuilder
public AbstractHttpFileBuilder()
-
-
Method Details
-
clock
Returns theClock
that provides the current date and time. -
clock
Sets theClock
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
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
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
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 @Nullable BiFunction<String,HttpFileAttributes, entityTagFunction()String> 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
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. UseentityTag(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, ornull
to disable setting the"etag"
header.
-
buildHeaders
Returns the immutable additionalHttpHeaders
which will be set when building anHttpResponse
. -
addHeader
Adds the specified HTTP header. -
addHeaders
public AbstractHttpFileBuilder addHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) Adds the specified HTTP headers. -
setHeader
Sets the specified HTTP header. -
setHeaders
public AbstractHttpFileBuilder setHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> headers) Sets the specified HTTP headers. -
contentType
Sets the"content-type"
header. This method is a shortcut for:builder.autoDetectedContentType(false); builder.setHeader(HttpHeaderNames.CONTENT_TYPE, contentType);
-
contentType
Sets the"content-type"
header. This method is a shortcut for:builder.autoDetectedContentType(false); builder.setHeader(HttpHeaderNames.CONTENT_TYPE, contentType);
-
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);
-