public interface ResponseHeaders extends Headers
Parameters interface by adding HTTP response headers oriented constants and convenient methods.
Use constants located in Http.Header as standard header names.
send 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.
Http.Header| Modifier and Type | Method and Description |
|---|---|
java.util.List<MediaType> |
acceptPatches()
Gets immutable list of supported patch document formats (header "Accept-Patch").
|
void |
addAcceptPatches(MediaType... acceptableMediaTypes)
Adds one or more acceptedTypes path document formats (header "Accept-Patch").
|
void |
addCookie(SetCookie cookie)
Adds
Set-Cookie header specified in RFC6265. |
void |
addCookie(java.lang.String name,
java.lang.String value)
Adds
Set-Cookie header based on RFC2616. |
void |
addCookie(java.lang.String name,
java.lang.String value,
java.time.Duration maxAge)
|
void |
beforeSend(java.util.function.Consumer<ResponseHeaders> headersConsumer)
Register a
Consumer which is executed just before headers are send. |
java.util.OptionalLong |
contentLength()
Optionally gets the value of "Content-Length" header.
|
void |
contentLength(long contentLength)
Sets the value of "Content-Length" header.
|
java.util.Optional<MediaType> |
contentType()
Optionally gets the MIME type of the response body.
|
void |
contentType(MediaType contentType)
Sets the MIME type of the response body.
|
java.util.Optional<java.time.ZonedDateTime> |
expires()
Optionally gets the value of "Expires" header.
|
void |
expires(java.time.Instant dateTime)
Sets the value of "Expires" header.
|
void |
expires(java.time.ZonedDateTime dateTime)
Sets the value of "Expires" header.
|
java.util.Optional<java.time.ZonedDateTime> |
lastModified()
Optionally gets the value of "Last-Modified" header.
|
void |
lastModified(java.time.Instant dateTime)
Sets the value of "Last-Modified" header.
|
void |
lastModified(java.time.ZonedDateTime dateTime)
Sets the value of "Last-Modified" header.
|
java.util.Optional<java.net.URI> |
location()
Optionally gets the value of "Location" header.
|
void |
location(java.net.URI location)
Sets the value of "Location" header.
|
java.util.concurrent.CompletionStage<ResponseHeaders> |
send()
Send headers and status code to the client.
|
java.util.concurrent.CompletionStage<ResponseHeaders> |
whenSend()
Returns a completion stage which is completed when all headers are send to the client.
|
add, add, addAll, computeIfAbsent, computeSingleIfAbsent, first, put, put, putAll, putIfAbsent, putIfAbsent, remove, toMap, toUnmodifiableParametersjava.util.List<MediaType> acceptPatches()
Method returns a copy of actual values.
void addAcceptPatches(MediaType... acceptableMediaTypes) throws AlreadyCompletedException
acceptableMediaTypes - media types to add.AlreadyCompletedException - if headers were completed (sent to the client).java.util.Optional<MediaType> contentType()
void contentType(MediaType contentType) throws AlreadyCompletedException
contentType - Media type of the content.AlreadyCompletedException - if headers were completed (sent to the client).java.util.OptionalLong contentLength()
void contentLength(long contentLength)
throws AlreadyCompletedException
contentLength - Length of the body in octets.AlreadyCompletedException - if headers were completed (sent to the client).java.util.Optional<java.time.ZonedDateTime> expires()
Gives the date/time after which the response is considered stale.
void expires(java.time.ZonedDateTime dateTime)
throws AlreadyCompletedException
The date/time after which the response is considered stale.
dateTime - Expires date/time.AlreadyCompletedException - if headers were completed (sent to the client).void expires(java.time.Instant dateTime)
throws AlreadyCompletedException
The date/time after which the response is considered stale.
dateTime - Expires date/time.AlreadyCompletedException - if headers were completed (sent to the client).java.util.Optional<java.time.ZonedDateTime> lastModified()
The last modified date for the requested object.
void lastModified(java.time.ZonedDateTime dateTime)
throws AlreadyCompletedException
The last modified date for the requested object.
dateTime - Expires date/time.AlreadyCompletedException - if headers were completed (sent to the client).void lastModified(java.time.Instant dateTime)
throws AlreadyCompletedException
The last modified date for the requested object
dateTime - Expires date/time.AlreadyCompletedException - if headers were completed (sent to the client).java.util.Optional<java.net.URI> location()
Used in redirection, or when a new resource has been created.
void location(java.net.URI location)
throws AlreadyCompletedException
Used in redirection, or when a new resource has been created.
location - Location header value.AlreadyCompletedException - if headers were completed (sent to the client).void addCookie(java.lang.String name,
java.lang.String value)
throws AlreadyCompletedException,
java.lang.NullPointerException
Set-Cookie header based on RFC2616.name - a name of the cookie.value - a value of the cookie.java.lang.NullPointerException - if name parameter is null.AlreadyCompletedException - if headers were completed (sent to the client).void addCookie(java.lang.String name,
java.lang.String value,
java.time.Duration maxAge)
throws AlreadyCompletedException,
java.lang.NullPointerException
name - a name of the cookie.value - a value of the cookie.maxAge - a Max-Age cookie parameter.java.lang.NullPointerException - if name parameter is null.AlreadyCompletedException - if headers were completed (sent to the client).void addCookie(SetCookie cookie) throws java.lang.NullPointerException
Set-Cookie header specified in RFC6265.cookie - a cookie definitionjava.lang.NullPointerException - if cookie parameter is nullvoid beforeSend(java.util.function.Consumer<ResponseHeaders> headersConsumer)
Consumer 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.
headersConsumer - a consumer which will be executed just before headers are send.java.util.concurrent.CompletionStage<ResponseHeaders> whenSend()
java.util.concurrent.CompletionStage<ResponseHeaders> send()
IllegalStateException).
It is non-blocking method returning a CompletionStage.
Copyright © 2018–2019 Oracle Corporation. All rights reserved.