- All Known Subinterfaces:
RoutingResponse
- All Known Implementing Classes:
ServerResponseBase
public interface ServerResponse
Http server response.
-
Method Summary
Modifier and TypeMethodDescriptionlong
Number of bytes written to response.default void
contentLength
(long length) Configure a content length header for this response.Set header with a value.default ServerResponse
header
(HeaderName name, String... values) Set a header.default ServerResponse
Not optimized method for setting a header.headers()
Response headers (mutable).boolean
isSent()
Whether this response has been sent.next()
Continue processing with the next route (and if none found, return aStatus.NOT_FOUND_404
).Alternative way to send an entity, using an output stream.Re-route using a different path.Re-route using a different path and query.void
send()
Send a response with no entity.void
send
(byte[] bytes) Send a byte array response.default void
send
(byte[] bytes, int position, int length) Send a byte array response.void
Send an entity, aMediaContext
will be used to serialize the entity.default void
Send an entity if present, throwNotFoundException
if empty.default <T extends Sink<?>>
Tsink
(GenericType<T> sinkType) Returns a sink from this response based on the sink type, if available.status()
Configured HTTP status, if not configured, returnsStatus.OK_200
.default ServerResponse
status
(int status) Status of the response.Status of the response.void
streamFilter
(UnaryOperator<OutputStream> filterFunction) Configure a custom output stream to wrap the output stream of the response.void
streamResult
(String result) Description of the result of output stream processing.trailers()
Response trailers (mutable).Completed when last byte is buffered for socket write.
-
Method Details
-
status
Status of the response.- Parameters:
status
- HTTP status- Returns:
- this instance
-
status
Status of the response.- Parameters:
status
- HTTP status as integer- Returns:
- this instance
-
status
Status status()Configured HTTP status, if not configured, returnsStatus.OK_200
.- Returns:
- status
-
header
Set a header. If the values are constant, please useHeaderValues.create(io.helidon.http.HeaderName, String...)
and store the header in a constant field and callheader(io.helidon.http.Header)
.- Parameters:
name
- header namevalues
- value(s) of the header- Returns:
- this instance
-
header
Not optimized method for setting a header. Use for unknown headers, whereHeaderName
cannot be cached. Useheader(io.helidon.http.Header)
orheader(HeaderName, String...)
otherwise.- Parameters:
name
- name of the headervalues
- values of the header- Returns:
- this instance
-
header
Set header with a value. Headers cannot be set afteroutputStream()
method is called, or after the response was sent.- Parameters:
header
- header value- Returns:
- this instance
- Throws:
IllegalStateException
- in case a header is set after output stream was requested, or the response was sent- See Also:
-
send
void send()Send a response with no entity. -
send
void send(byte[] bytes) Send a byte array response.- Parameters:
bytes
- bytes to send
-
send
default void send(byte[] bytes, int position, int length) Send a byte array response.- Parameters:
bytes
- bytes to sendposition
- starting positionlength
- number of bytes send
-
send
Send an entity, aMediaContext
will be used to serialize the entity.- Parameters:
entity
- entity object
-
send
Send an entity if present, throwNotFoundException
if empty.- Parameters:
entity
- entity as an optional
-
isSent
boolean isSent()Whether this response has been sent.- Returns:
- whether sent
-
outputStream
OutputStream outputStream()Alternative way to send an entity, using an output stream. This should be used for entities that are big and that should not be materialized into memory.- Returns:
- output stream
-
bytesWritten
long bytesWritten()Number of bytes written to response. Only available once the response is sent.- Returns:
- bytes written (combination of all bytes of status, headers and entity)
-
whenSent
Completed when last byte is buffered for socket write.- Parameters:
listener
- listener to add to list of listeners that will be triggered once response is sent- Returns:
- this instance
-
reroute
Re-route using a different path.- Parameters:
newPath
- new path to use- Returns:
- this instance
-
reroute
Re-route using a different path and query.- Parameters:
path
- new pathquery
- new query- Returns:
- this instance
- Throws:
IllegalStateException
- in case the entity was already configured- See Also:
-
next
ServerResponse next()Continue processing with the next route (and if none found, return aStatus.NOT_FOUND_404
). If any entity method was called, this method will throw an exception.- Returns:
- this instance
- Throws:
IllegalStateException
- in case the entity was already configured
-
headers
ServerResponseHeaders headers()Response headers (mutable).- Returns:
- headers
-
trailers
ServerResponseTrailers trailers()Response trailers (mutable).- Returns:
- trailers
- Throws:
IllegalStateException
- if client didn't ask for trailers withTE: trailers
header in request or response doesn't contain trailer declaration headersTrailer: <trailer-name>
-
streamResult
Description of the result of output stream processing. In case an output stream was used, calling this method will immediately close the stream and return this message as the reason for closing the response. In HTTP/1 this would be in a trailer header- Parameters:
result
- result description
-
contentLength
default void contentLength(long length) Configure a content length header for this response.- Parameters:
length
- content length
-
sink
Returns a sink from this response based on the sink type, if available.- Type Parameters:
T
- type of sink returned- Parameters:
sinkType
- type of sink- Returns:
- sink or
null
if not available
-
streamFilter
Configure a custom output stream to wrap the output stream of the response.- Parameters:
filterFunction
- the function to replace output stream of this response with a user provided one
-