Class Response.Wrapper
- All Implemented Interfaces:
Content.Sink
,Response
- Direct Known Subclasses:
ContextResponse
,GzipResponseAndCallback
,ServerUpgradeResponseDelegate
,ServerUpgradeResponseImpl
,StatisticsHandler.MinimumDataRateHandler.MinimumDataRateResponse
- Enclosing interface:
- Response
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.server.Response
Response.Wrapper
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
boolean
Returns whether the last write has been initiated on the response.boolean
Returns whether this response has already been committed.boolean
Returns whether the response completed successfully.void
reset()
Resets this response, clearing the HTTP status code, HTTP headers and HTTP trailers.void
setStatus
(int code) Set the response HTTP status code.void
setTrailersSupplier
(Supplier<HttpFields> trailers) Sets the supplier for the HTTP trailers.void
write
(boolean last, ByteBuffer byteBuffer, Callback callback) Writes the givenByteBuffer
, notifying theCallback
when the write is complete.writeInterim
(int status, HttpFields headers) Writes anHTTP interim response
, with the given HTTP status code and HTTP headers.
-
Constructor Details
-
Wrapper
-
-
Method Details
-
getWrapped
-
getRequest
- Specified by:
getRequest
in interfaceResponse
- Returns:
- the
Request
associated with thisResponse
-
getStatus
public int getStatus() -
setStatus
public void setStatus(int code) Description copied from interface:Response
Set the response HTTP status code. -
getHeaders
- Specified by:
getHeaders
in interfaceResponse
- Returns:
- the response HTTP headers
-
getTrailersSupplier
- Specified by:
getTrailersSupplier
in interfaceResponse
- Returns:
- a supplier for the HTTP trailers
-
setTrailersSupplier
Description copied from interface:Response
Sets the supplier for the HTTP trailers.
The method
Supplier.get()
may be called by the implementation multiple times, so it is important that the same value is returned in every invocation.Example:
// Correct usage. HttpFields.Mutable trailers = HttpFields.build(); response.setTrailersSupplier(() -> trailers); // WRONG usage, as the value changes for // every invocation of supplier.get(). response.setTrailersSupplier(() -> HttpFields.build());
- Specified by:
setTrailersSupplier
in interfaceResponse
- Parameters:
trailers
- a supplier for the HTTP trailers
-
isCommitted
public boolean isCommitted()Description copied from interface:Response
Returns whether this response has already been committed.
Committing a response means that the HTTP status code and HTTP headers cannot be modified anymore, typically because they have already been serialized and sent over the network.
- Specified by:
isCommitted
in interfaceResponse
- Returns:
- whether this response has already been committed
-
hasLastWrite
public boolean hasLastWrite()Description copied from interface:Response
Returns whether the last write has been initiated on the response.
- Specified by:
hasLastWrite
in interfaceResponse
- Returns:
true
iflast==true
has been passed toResponse.write(boolean, ByteBuffer, Callback)
.
-
isCompletedSuccessfully
public boolean isCompletedSuccessfully()Description copied from interface:Response
Returns whether the response completed successfully.
The response HTTP status code, HTTP headers and content have been successfully serialized and sent over the network without errors.
- Specified by:
isCompletedSuccessfully
in interfaceResponse
- Returns:
- whether the response completed successfully
-
reset
public void reset()Description copied from interface:Response
Resets this response, clearing the HTTP status code, HTTP headers and HTTP trailers.
-
writeInterim
Description copied from interface:Response
Writes an
HTTP interim response
, with the given HTTP status code and HTTP headers.It is possible to write more than one interim response, for example in case of
HttpStatus.EARLY_HINTS_103
.The returned
CompletableFuture
is notified of the result of this write, whether it succeeded or failed.- Specified by:
writeInterim
in interfaceResponse
- Parameters:
status
- the interim HTTP status codeheaders
- the HTTP headers- Returns:
- a
CompletableFuture
with the result of the write
-
write
Description copied from interface:Response
Writes the given
ByteBuffer
, notifying theCallback
when the write is complete.Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the
Callback
and a call to this method.The invocation of the passed
Callback
is serialized with previous calls of this method, so that it is not invoked until any invocation of the callback of a previous call to this method has returned.Thus a
Callback
should not block waiting for a callback of a future call to this method.- Specified by:
write
in interfaceContent.Sink
- Specified by:
write
in interfaceResponse
- Parameters:
last
- whether the ByteBuffer is the last to writebyteBuffer
- the ByteBuffer to writecallback
- the callback to notify when the write operation is complete
-