Module io.helidon.webserver
Package io.helidon.webserver.http
Class ServerResponseBase<T extends ServerResponseBase<T>>
java.lang.Object
io.helidon.webserver.http.ServerResponseBase<T>
- Type Parameters:
T
- type of the response extending this class to allow fluent API
- All Implemented Interfaces:
RoutingResponse
,ServerResponse
public abstract class ServerResponseBase<T extends ServerResponseBase<T>>
extends Object
implements RoutingResponse
Base class for common server response tasks that can be shared across HTTP versions.
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final HeaderName
Stream result trailer name.protected static final Header
Stream status trailers. -
Constructor Summary
ModifierConstructorDescriptionprotected
ServerResponseBase
(ConnectionContext ctx, ServerRequest request) Create server response. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Execute after send runnables.protected OutputStream
contentEncode
(OutputStream outputStream) Encode content using requested/default content encoder.protected byte[]
entityBytes
(byte[] configuredEntity) Entity bytes encoded using content encoding.boolean
isNexted()
Whether this request is nexted (ServerResponse.next()
was called).protected MediaContext
Gets media context for this response.next()
Continue processing with the next route (and if none found, return aStatus.NOT_FOUND_404
).Re-route using a different path.Re-route using a different path and query.reroutePrologue
(HttpPrologue prologue) A new, rerouted prologue.void
Reset routing information (nexted, rerouted etc.).void
send()
Send a response with no entity.void
Send an entity, aMediaContext
will be used to serialize the entity.boolean
Should we reroute this exchange.status()
Configured HTTP status, if not configured, returnsStatus.OK_200
.Status of the response.Completed when last byte is buffered for socket write.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.helidon.webserver.http.RoutingResponse
commit, hasEntity, reset
Methods inherited from interface io.helidon.webserver.http.ServerResponse
bytesWritten, contentLength, header, header, header, headers, isSent, outputStream, send, send, sink, status, streamFilter, streamResult, trailers
-
Field Details
-
STREAM_RESULT_NAME
Stream result trailer name. -
STREAM_TRAILERS
Stream status trailers.
-
-
Constructor Details
-
ServerResponseBase
Create server response.- Parameters:
ctx
- contextrequest
- server request
-
-
Method Details
-
status
Description copied from interface:ServerResponse
Status of the response.- Specified by:
status
in interfaceServerResponse
- Parameters:
status
- HTTP status- Returns:
- this instance
-
status
Description copied from interface:ServerResponse
Configured HTTP status, if not configured, returnsStatus.OK_200
.- Specified by:
status
in interfaceServerResponse
- Returns:
- status
-
send
public void send()Description copied from interface:ServerResponse
Send a response with no entity.- Specified by:
send
in interfaceServerResponse
-
send
Description copied from interface:ServerResponse
Send an entity, aMediaContext
will be used to serialize the entity.- Specified by:
send
in interfaceServerResponse
- Parameters:
entity
- entity object
-
whenSent
Description copied from interface:ServerResponse
Completed when last byte is buffered for socket write.- Specified by:
whenSent
in interfaceServerResponse
- Parameters:
listener
- listener to add to list of listeners that will be triggered once response is sent- Returns:
- this instance
-
reroute
Description copied from interface:ServerResponse
Re-route using a different path.- Specified by:
reroute
in interfaceServerResponse
- Parameters:
newPath
- new path to use- Returns:
- this instance
-
reroute
Description copied from interface:ServerResponse
Re-route using a different path and query.- Specified by:
reroute
in interfaceServerResponse
- Parameters:
path
- new pathquery
- new query- Returns:
- this instance
- See Also:
-
next
Description copied from interface:ServerResponse
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.- Specified by:
next
in interfaceServerResponse
- Returns:
- this instance
-
resetRouting
public void resetRouting()Description copied from interface:RoutingResponse
Reset routing information (nexted, rerouted etc.).- Specified by:
resetRouting
in interfaceRoutingResponse
-
shouldReroute
public boolean shouldReroute()Description copied from interface:RoutingResponse
Should we reroute this exchange.- Specified by:
shouldReroute
in interfaceRoutingResponse
- Returns:
- whether rerouting was requested
-
reroutePrologue
Description copied from interface:RoutingResponse
A new, rerouted prologue.- Specified by:
reroutePrologue
in interfaceRoutingResponse
- Parameters:
prologue
- current prologue- Returns:
- prologue to use when rerouting
-
isNexted
public boolean isNexted()Description copied from interface:RoutingResponse
Whether this request is nexted (ServerResponse.next()
was called).- Specified by:
isNexted
in interfaceRoutingResponse
- Returns:
- if nexted
-
mediaContext
Gets media context for this response.- Returns:
- the media context
-
entityBytes
protected byte[] entityBytes(byte[] configuredEntity) Entity bytes encoded using content encoding. Does not attempt encoding if entity is empty.- Parameters:
configuredEntity
- plain bytes- Returns:
- encoded bytes
-
contentEncode
Encode content using requested/default content encoder.- Parameters:
outputStream
- output stream to write encoded data to- Returns:
- output stream to write plain data to
-
afterSend
protected void afterSend()Execute after send runnables.
-