Parameters interface by adding HTTP response headers oriented constants and convenient methods.
Use constants located in Http.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:
-
Method Summary
Modifier and TypeMethodDescriptionGets immutable list of supported patch document formats (header "Accept-Patch").Adds specified values to association with the specified key (optional operation).Adds specified values to association with the specified key (optional operation).voidaddAcceptPatches(MediaType... acceptableMediaTypes) Adds one or more acceptedTypes path document formats (header "Accept-Patch").addAll(Parameters parameters) Copies all of the mappings from the specifiedparametersto this instance adding values to existing associations (optional operation).voidAddsSet-Cookieheader specified in RFC6265.voidAddsSet-Cookieheader based on RFC2616.voidvoidbeforeSend(Consumer<ResponseHeaders> headersConsumer) Register aConsumerwhich is executed just before headers are send.voidclearCookie(String name) Clears a cookie by adding aSet-Cookieheader with an expiration date in the past.Optionally gets the value of "Content-Length" header.voidcontentLength(long contentLength) Sets the value of "Content-Length" header.Optionally gets the MIME type of the response body.voidcontentType(MediaType contentType) Sets the MIME type of the response body.expires()Optionally gets the value of "Expires" header.voidSets the value of "Expires" header.voidexpires(ZonedDateTime dateTime) Sets the value of "Expires" header.Optionally gets the value of "Last-Modified" header.voidlastModified(Instant dateTime) Sets the value of "Last-Modified" header.voidlastModified(ZonedDateTime dateTime) Sets the value of "Last-Modified" header.location()Optionally gets the value of "Location" header.voidSets the value of "Location" header.putAll(Parameters parameters) Copies all of the mappings from the specifiedparametersto this instance replacing values of existing associations (optional operation).send()Send headers and status code to the client.default Single<ResponseHeaders>whenSend()Deprecated.whenSent()Returns aSinglewhich is completed when all headers are sent to the client.Methods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface io.helidon.common.http.Parameters
computeIfAbsent, computeSingleIfAbsent, first, iterator, put, put, putIfAbsent, putIfAbsent, remove, toMap
-
Method Details
-
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
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
Optionally gets the MIME type of the response body.- Returns:
- Media type of the content.
-
contentType
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
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
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
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
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
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
Optionally gets the value of "Location" header.Used in redirection, or when a new resource has been created.
- Returns:
- Location header value.
-
location
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
AddsSet-Cookieheader based on RFC2616.- Parameters:
name- a name of the cookie.value- a value of the cookie.- Throws:
NullPointerException- ifnameparameter 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-Agecookie parameter.- Throws:
NullPointerException- ifnameparameter isnull.AlreadyCompletedException- if headers were completed (sent to the client).
-
addCookie
AddsSet-Cookieheader specified in RFC6265.- Parameters:
cookie- a cookie definition- Throws:
NullPointerException- ifcookieparameter isnull
-
clearCookie
Clears a cookie by adding aSet-Cookieheader with an expiration date in the past.- Parameters:
name- name of the cookie.
-
beforeSend
Register aConsumerwhich is executed just before headers are send.Consumercan 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.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 aSinglewhich 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
Description copied from interface:ParametersCopies all of the mappings from the specifiedparametersto this instance replacing values of existing associations (optional operation).- Specified by:
putAllin interfaceParameters- Parameters:
parameters- to copy.- Returns:
- this instance of
Parameters
-
add
Description copied from interface:ParametersAdds specified values to association with the specified key (optional operation). If parameters doesn't contains mapping, new mapping is created.- Specified by:
addin 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
Description copied from interface:ParametersAdds specified values to association with the specified key (optional operation). If parameters doesn't contains mapping, new mapping is created.- Specified by:
addin interfaceParameters- Parameters:
key- key with which the specified value is to be associatedvalues- value to be add to association with the specified key. Ifnullthen noting will be add.- Returns:
- this instance of
Parameters
-
addAll
Description copied from interface:ParametersCopies all of the mappings from the specifiedparametersto this instance adding values to existing associations (optional operation).- Specified by:
addAllin interfaceParameters- Parameters:
parameters- to copy.- Returns:
- this instance of
Parameters
-
whenSent()