-
- All Superinterfaces:
Headers
,Parameters
public interface ResponseHeaders extends Headers
ExtendsParameters
interface by adding HTTP response headers oriented constants and convenient methods. Use constants located inHttp.Header
as standard header names.Lifecycle
Headers can be muted untilsend
to the client. It is also possible to register a 'before send
' function which can made 'last minute mutation'.Headers are send together with HTTP status code also automatically just before first chunk of response data is send.
- See Also:
Http.Header
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description List<MediaType>
acceptPatches()
Gets immutable list of supported patch document formats (header "Accept-Patch").ResponseHeaders
add(String key, Iterable<String> values)
Adds specified values tu association with the specified key (optional operation).ResponseHeaders
add(String key, String... values)
Adds specified values tu association with the specified key (optional operation).void
addAcceptPatches(MediaType... acceptableMediaTypes)
Adds one or more acceptedTypes path document formats (header "Accept-Patch").ResponseHeaders
addAll(Parameters parameters)
Copies all of the mappings from the specifiedparameters
to this instance adding values to existing associations (optional operation).void
addCookie(SetCookie cookie)
AddsSet-Cookie
header specified in RFC6265.void
addCookie(String name, String value)
AddsSet-Cookie
header based on RFC2616.void
addCookie(String name, String value, Duration maxAge)
void
beforeSend(Consumer<ResponseHeaders> headersConsumer)
Register aConsumer
which is executed just before headers are send.void
clearCookie(String name)
Clears a cookie by adding aSet-Cookie
header with an expiration date in the past.OptionalLong
contentLength()
Optionally gets the value of "Content-Length" header.void
contentLength(long contentLength)
Sets the value of "Content-Length" header.Optional<MediaType>
contentType()
Optionally gets the MIME type of the response body.void
contentType(MediaType contentType)
Sets the MIME type of the response body.Optional<ZonedDateTime>
expires()
Optionally gets the value of "Expires" header.void
expires(Instant dateTime)
Sets the value of "Expires" header.void
expires(ZonedDateTime dateTime)
Sets the value of "Expires" header.Optional<ZonedDateTime>
lastModified()
Optionally gets the value of "Last-Modified" header.void
lastModified(Instant dateTime)
Sets the value of "Last-Modified" header.void
lastModified(ZonedDateTime dateTime)
Sets the value of "Last-Modified" header.Optional<URI>
location()
Optionally gets the value of "Location" header.void
location(URI location)
Sets the value of "Location" header.ResponseHeaders
putAll(Parameters parameters)
Copies all of the mappings from the specifiedparameters
to this instance replacing values of existing associations (optional operation).Single<ResponseHeaders>
send()
Send headers and status code to the client.default Single<ResponseHeaders>
whenSend()
Deprecated.since 2.0.0, please usewhenSent()
Single<ResponseHeaders>
whenSent()
Returns aSingle
which is completed when all headers are sent to the client.-
Methods inherited from interface io.helidon.common.http.Parameters
computeIfAbsent, computeSingleIfAbsent, first, put, put, putIfAbsent, putIfAbsent, remove, toMap
-
-
-
-
Method Detail
-
acceptPatches
List<MediaType> acceptPatches()
Gets immutable list of supported patch document formats (header "Accept-Patch").Method returns a copy of actual values.
- Returns:
- A list of supported media types for the patch.
-
addAcceptPatches
void addAcceptPatches(MediaType... acceptableMediaTypes) throws AlreadyCompletedException
Adds one or more acceptedTypes path document formats (header "Accept-Patch").- Parameters:
acceptableMediaTypes
- media types to add.- Throws:
AlreadyCompletedException
- if headers were completed (sent to the client).
-
contentType
Optional<MediaType> contentType()
Optionally gets the MIME type of the response body.- Returns:
- Media type of the content.
-
contentType
void contentType(MediaType contentType) throws AlreadyCompletedException
Sets the MIME type of the response body.- Parameters:
contentType
- Media type of the content.- Throws:
AlreadyCompletedException
- if headers were completed (sent to the client).
-
contentLength
OptionalLong contentLength()
Optionally gets the value of "Content-Length" header.- Returns:
- Length of the body in octets.
-
contentLength
void contentLength(long contentLength) throws AlreadyCompletedException
Sets the value of "Content-Length" header.- Parameters:
contentLength
- Length of the body in octets.- Throws:
AlreadyCompletedException
- if headers were completed (sent to the client).
-
expires
Optional<ZonedDateTime> expires()
Optionally gets the value of "Expires" header.Gives the date/time after which the response is considered stale.
- Returns:
- Expires header value.
-
expires
void expires(ZonedDateTime dateTime) throws AlreadyCompletedException
Sets the value of "Expires" header.The date/time after which the response is considered stale.
- Parameters:
dateTime
- Expires date/time.- Throws:
AlreadyCompletedException
- if headers were completed (sent to the client).
-
expires
void expires(Instant dateTime) throws AlreadyCompletedException
Sets the value of "Expires" header.The date/time after which the response is considered stale.
- Parameters:
dateTime
- Expires date/time.- Throws:
AlreadyCompletedException
- if headers were completed (sent to the client).
-
lastModified
Optional<ZonedDateTime> lastModified()
Optionally gets the value of "Last-Modified" header.The last modified date for the requested object.
- Returns:
- Expires header value.
-
lastModified
void lastModified(ZonedDateTime dateTime) throws AlreadyCompletedException
Sets the value of "Last-Modified" header.The last modified date for the requested object.
- Parameters:
dateTime
- Expires date/time.- Throws:
AlreadyCompletedException
- if headers were completed (sent to the client).
-
lastModified
void lastModified(Instant dateTime) throws AlreadyCompletedException
Sets the value of "Last-Modified" header.The last modified date for the requested object
- Parameters:
dateTime
- Expires date/time.- Throws:
AlreadyCompletedException
- if headers were completed (sent to the client).
-
location
Optional<URI> location()
Optionally gets the value of "Location" header.Used in redirection, or when a new resource has been created.
- Returns:
- Location header value.
-
location
void location(URI location) throws AlreadyCompletedException
Sets the value of "Location" header.Used in redirection, or when a new resource has been created.
- Parameters:
location
- Location header value.- Throws:
AlreadyCompletedException
- if headers were completed (sent to the client).
-
addCookie
void addCookie(String name, String value) throws AlreadyCompletedException, NullPointerException
AddsSet-Cookie
header based on RFC2616.- Parameters:
name
- a name of the cookie.value
- a value of the cookie.- Throws:
NullPointerException
- ifname
parameter isnull
.AlreadyCompletedException
- if headers were completed (sent to the client).
-
addCookie
void addCookie(String name, String value, Duration maxAge) throws AlreadyCompletedException, NullPointerException
- Parameters:
name
- a name of the cookie.value
- a value of the cookie.maxAge
- aMax-Age
cookie parameter.- Throws:
NullPointerException
- ifname
parameter isnull
.AlreadyCompletedException
- if headers were completed (sent to the client).
-
addCookie
void addCookie(SetCookie cookie) throws NullPointerException
AddsSet-Cookie
header specified in RFC6265.- Parameters:
cookie
- a cookie definition- Throws:
NullPointerException
- ifcookie
parameter isnull
-
clearCookie
void clearCookie(String name)
Clears a cookie by adding aSet-Cookie
header with an expiration date in the past.- Parameters:
name
- name of the cookie.
-
beforeSend
void beforeSend(Consumer<ResponseHeaders> headersConsumer)
Register aConsumer
which is executed just before headers are send.Consumer
can made 'last minute changes' in headers.Sending of headers to the client is postponed after all registered consumers are finished.
There is no guarantied execution order.
- Parameters:
headersConsumer
- a consumer which will be executed just before headers are send.
-
whenSend
@Deprecated default Single<ResponseHeaders> whenSend()
Deprecated.since 2.0.0, please usewhenSent()
Returns a completion stage which is completed when all headers are send to the client.- Returns:
- a completion stage of the headers.
-
whenSent
Single<ResponseHeaders> whenSent()
Returns aSingle
which is completed when all headers are sent to the client.- Returns:
- a single of the headers
-
send
Single<ResponseHeaders> send()
Send headers and status code to the client. This instance become immutable after that (all muting methods throwsIllegalStateException
).It is non-blocking method returning a
Single
.- Returns:
- a completion stage of sending process.
-
putAll
ResponseHeaders putAll(Parameters parameters)
Description copied from interface:Parameters
Copies all of the mappings from the specifiedparameters
to this instance replacing values of existing associations (optional operation).- Specified by:
putAll
in interfaceParameters
- Parameters:
parameters
- to copy.- Returns:
- this instance of
Parameters
-
add
ResponseHeaders add(String key, String... values)
Description copied from interface:Parameters
Adds specified values tu association with the specified key (optional operation). If parameters doesn't contains mapping, new mapping is created.- Specified by:
add
in interfaceParameters
- Parameters:
key
- key with which the specified value is to be associatedvalues
- value to be add to association with the specified key- Returns:
- this instance of
Parameters
-
add
ResponseHeaders add(String key, Iterable<String> values)
Description copied from interface:Parameters
Adds specified values tu association with the specified key (optional operation). If parameters doesn't contains mapping, new mapping is created.- Specified by:
add
in interfaceParameters
- Parameters:
key
- key with which the specified value is to be associatedvalues
- value to be add to association with the specified key. Ifnull
then noting will be add.- Returns:
- this instance of
Parameters
-
addAll
ResponseHeaders addAll(Parameters parameters)
Description copied from interface:Parameters
Copies all of the mappings from the specifiedparameters
to this instance adding values to existing associations (optional operation).- Specified by:
addAll
in interfaceParameters
- Parameters:
parameters
- to copy.- Returns:
- this instance of
Parameters
-
-