Struct SendResponse
pub struct SendResponse<B: Buf> { /* private fields */ }
Send a response back to the client
A SendResponse instance is provided when receiving a request and is used
to send the associated response back to the client. It is also used to
explicitly reset the stream with a custom reason.
It will also be used to initiate push promises linked with the associated stream.
If the SendResponse instance is dropped without sending a response, then
the HTTP/2 stream will be reset.
See module level docs for more details.
Implementations
impl<B: Buf> SendResponse<B>
fn send_informational(&mut self, response: Response<()>) -> Result<(), Error>Send an interim informational response (1xx status codes)
This method can be called multiple times before calling
send_response()to send the final response. Only 1xx status codes are allowed.Interim informational responses are used to provide early feedback to the client before the final response is ready. Common examples include:
- 100 Continue: Indicates the client should continue with the request
- 103 Early Hints: Provides early hints about resources to preload
Arguments
response- HTTP response with 1xx status code and headers
Returns
Ok(())- Interim Informational response sent successfullyErr(Error)- Failed to send (invalid status code, connection error, etc.)
Examples
use server; use ; # asyncErrors
This method will return an error if:
- The response status code is not in the 1xx range
- The final response has already been sent
- There is a connection-level error
fn send_response(&mut self, response: Response<()>, end_of_stream: bool) -> Result<SendStream<B>, Error>Send a response to a client request.
On success, a
SendStreaminstance is returned. This instance can be used to stream the response body and send trailers.If a body or trailers will be sent on the returned
SendStreaminstance, thenend_of_streammust be set tofalsewhen calling this function.The
SendResponseinstance is already associated with a received request. This function may only be called once per instance and only ifsend_resethas not been previously called.fn push_request(&mut self, request: Request<()>) -> Result<SendPushedResponse<B>, Error>Push a request and response to the client
On success, a
SendResponseinstance is returned.fn send_reset(&mut self, reason: Reason)Send a stream reset to the peer.
This essentially cancels the stream, including any inbound or outbound data streams.
If this function is called before
send_response, a call tosend_responsewill result in an error.If this function is called while a
SendStreaminstance is active, any further use of the instance will result in an error.This function should only be called once.
fn poll_reset(&mut self, cx: &mut Context<'_>) -> Poll<Result<Reason, Error>>Polls to be notified when the client resets this stream.
If stream is still open, this returns
Poll::Pending, and registers the task to be notified if aRST_STREAMis received.If a
RST_STREAMframe is received for this stream, calling this method will yield theReasonfor the reset.Error
Calling this method after having called
send_responsewill return a user error.fn stream_id(&self) -> StreamIdReturns the stream ID of the response stream.
Panics
If the lock on the stream store has been poisoned.
Trait Implementations
impl<B: Debug + Buf> Debug for SendResponse<B>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<B> Freeze for SendResponse<B>
where
StreamRef<B>: Freeze,
impl<B> RefUnwindSafe for SendResponse<B>
where
StreamRef<B>: RefUnwindSafe,
impl<B> Send for SendResponse<B>
where
StreamRef<B>: Send,
impl<B> Sync for SendResponse<B>
where
StreamRef<B>: Sync,
impl<B> Unpin for SendResponse<B>
where
StreamRef<B>: Unpin,
impl<B> UnsafeUnpin for SendResponse<B>
where
StreamRef<B>: UnsafeUnpin,
impl<B> UnwindSafe for SendResponse<B>
where
StreamRef<B>: UnwindSafe,
Blanket Implementations
impl<T> Any for SendResponse<B>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for SendResponse<B>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for SendResponse<B>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for SendResponse<B>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for SendResponse<B>
impl<T> WithSubscriber for SendResponse<B>
impl<T, U> Into<U> for SendResponse<B>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for SendResponse<B>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for SendResponse<B>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>