Class HttpChannelState.ChannelResponse
- All Implemented Interfaces:
Content.Sink,Response,Callback,Invocable
- Enclosing class:
HttpChannelState
Response API.
Also is a Callback used by the write(boolean, ByteBuffer, Callback)
method when calling
HttpStream.send(MetaData.Request, MetaData.Response, boolean, ByteBuffer, Callback)-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Callback
Callback.Completable, Callback.Completing, Callback.NestedNested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.TaskNested classes/interfaces inherited from interface org.eclipse.jetty.server.Response
Response.Wrapper -
Field Summary
FieldsFields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled when the call toHttpStream.send(MetaData.Request, MetaData.Response, boolean, ByteBuffer, Callback)made bywrite(boolean, ByteBuffer, Callback)fails.longprotected ResponseHttpFieldsprotected ResponseHttpFieldsgetResponseHttpFields(HttpChannelState httpChannelState) intbooleanReturns whether the last write has been initiated on the response.booleanReturns whether this response has already been committed.booleanReturns whether the response completed successfully.voidreset()Resets this response, clearing the HTTP status code, HTTP headers and HTTP trailers.voidsetStatus(int code) Set the response HTTP status code.voidsetTrailersSupplier(Supplier<HttpFields> trailers) Sets the supplier for the HTTP trailers.voidCalled when the call toHttpStream.send(MetaData.Request, MetaData.Response, boolean, ByteBuffer, Callback)made bywrite(boolean, ByteBuffer, Callback)succeeds.toString()voidwrite(boolean last, ByteBuffer content, Callback callback) Writes the givenByteBuffer, notifying theCallbackwhen the write is complete.writeInterim(int status, HttpFields headers) Writes anHTTP interim response, with the given HTTP status code and HTTP headers.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.Callback
completeWith
-
Field Details
-
_status
protected int _status
-
-
Method Details
-
getResponseHttpFields
-
getResponseHttpFields
-
getContentBytesWritten
public long getContentBytesWritten() -
getRequest
- Specified by:
getRequestin interfaceResponse- Returns:
- the
Requestassociated with thisResponse
-
getStatus
-
setStatus
-
getHeaders
- Specified by:
getHeadersin interfaceResponse- Returns:
- the response HTTP headers
-
getTrailersSupplier
- Specified by:
getTrailersSupplierin interfaceResponse- Returns:
- a supplier for the HTTP trailers
-
setTrailersSupplier
Description copied from interface:ResponseSets 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:
setTrailersSupplierin interfaceResponse- Parameters:
trailers- a supplier for the HTTP trailers
-
write
Description copied from interface:ResponseWrites the given
ByteBuffer, notifying theCallbackwhen 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
Callbackand a call to this method.The invocation of the passed
Callbackis 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
Callbackshould not block waiting for a callback of a future call to this method.- Specified by:
writein interfaceContent.Sink- Specified by:
writein interfaceResponse- Parameters:
last- whether the ByteBuffer is the last to writecontent- the ByteBuffer to writecallback- the callback to notify when the write operation is complete
-
succeeded
public void succeeded()Called when the call toHttpStream.send(MetaData.Request, MetaData.Response, boolean, ByteBuffer, Callback)made bywrite(boolean, ByteBuffer, Callback)succeeds. The implementation maintains theHttpChannelState._streamSendStatebefore taking and serializing the call to the_writeCallback, which was set by the call towrite. -
failed
Called when the call toHttpStream.send(MetaData.Request, MetaData.Response, boolean, ByteBuffer, Callback)made bywrite(boolean, ByteBuffer, Callback)fails.The implementation maintains the
HttpChannelState._streamSendStatebefore taking and serializing the call to the_writeCallback, which was set by the call towrite. -
getInvocationType
- Specified by:
getInvocationTypein interfaceInvocable- Returns:
- The InvocationType of this object
-
isCommitted
public boolean isCommitted()Description copied from interface:ResponseReturns 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:
isCommittedin interfaceResponse- Returns:
- whether this response has already been committed
-
hasLastWrite
public boolean hasLastWrite()Description copied from interface:ResponseReturns whether the last write has been initiated on the response.
- Specified by:
hasLastWritein interfaceResponse- Returns:
trueiflast==truehas been passed toResponse.write(boolean, ByteBuffer, Callback).
-
isCompletedSuccessfully
public boolean isCompletedSuccessfully()Description copied from interface:ResponseReturns 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:
isCompletedSuccessfullyin interfaceResponse- Returns:
- whether the response completed successfully
-
reset
-
writeInterim
Description copied from interface:ResponseWrites 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
CompletableFutureis notified of the result of this write, whether it succeeded or failed.- Specified by:
writeInterimin interfaceResponse- Parameters:
status- the interim HTTP status codeheaders- the HTTP headers- Returns:
- a
CompletableFuturewith the result of the write
-
toString
-