Struct SendRequest
pub struct SendRequest<B: Buf> { /* private fields */ }
Initializes new HTTP/2 streams on a connection by sending a request.
This type does no work itself. Instead, it is a handle to the inner
connection state held by Connection. If the associated connection
instance is dropped, all SendRequest functions will return Error.
SendRequest instances are able to move to and operate on separate tasks
/ threads than their associated Connection instance. Internally, there
is a buffer used to stage requests before they get written to the
connection. There is no guarantee that requests get written to the
connection in FIFO order as HTTP/2 prioritization logic can play a role.
SendRequest implements Clone, enabling the creation of many
instances that are backed by a single connection.
See module level documentation for more details.
Implementations
impl<B> SendRequest<B>
where
B: Buf,
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>Returns
Readywhen the connection can initialize a new HTTP/2 stream.This function must return
Readybeforesend_requestis called. WhenPoll::Pendingis returned, the task will be notified once the readiness state changes.See module level docs for more details.
fn ready(self) -> ReadySendRequest<B>Consumes
self, returning a future that returnsselfback once it is ready to send a request.This function should be called before calling
send_request.This is a functional combinator for
poll_ready. The returned future will callSendStream::poll_readyuntilReady, then returnsselfto the caller.Examples
# use *; # use *; # async # #See module level docs for more details.
fn send_request(&mut self, request: Request<()>, end_of_stream: bool) -> Result<(ResponseFuture, SendStream<B>), Error>Sends a HTTP/2 request to the server.
send_requestinitializes a new HTTP/2 stream on the associated connection, then sends the given request using this new stream. Only the request head is sent.On success, a
ResponseFutureinstance andSendStreaminstance are returned. TheResponseFutureinstance is used to get the server's response and theSendStreaminstance is used to send a request body or trailers to the server over the same HTTP/2 stream.To send a request body or trailers, set
end_of_streamtofalse. Then, use the returnedSendStreaminstance to stream request body chunks or send trailers. Ifend_of_streamis not set tofalsethen attempting to callSendStream::send_dataorSendStream::send_trailerswill result in an error.If no request body or trailers are to be sent, set
end_of_streamtotrueand drop the returnedSendStreaminstance.A note on HTTP versions
The provided
Requestwill be encoded differently depending on the value of its version field. If the version is set to 2.0, then the request is encoded as per the specification recommends.If the version is set to a lower value, then the request is encoded to preserve the characteristics of HTTP 1.1 and lower. Specifically, host headers are permitted and the
:authoritypseudo header is not included.The caller should always set the request's version field to 2.0 unless specifically transmitting an HTTP 1.1 request over 2.0.
Examples
Sending a request with no body
# use *; # use *; # async # #Sending a request with a body and trailers
# use *; # use *; # async # #fn is_extended_connect_protocol_enabled(&self) -> boolReturns whether the extended CONNECT protocol is enabled or not.
This setting is configured by the server peer by sending the
SETTINGS_ENABLE_CONNECT_PROTOCOLparameter in aSETTINGSframe. This method returns the currently acknowledged value received from the remote.fn current_max_send_streams(&self) -> usizeReturns the current max send streams
fn current_max_recv_streams(&self) -> usizeReturns the current max recv streams
Trait Implementations
impl<B> Clone for SendRequest<B>
where
B: Buf,
fn clone(&self) -> Self
impl<B> Debug for SendRequest<B>
where
B: Buf,
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<B> Freeze for SendRequest<B>
where
Streams<B, Peer>: Freeze,
impl<B> RefUnwindSafe for SendRequest<B>
where
Streams<B, Peer>: RefUnwindSafe,
impl<B> Send for SendRequest<B>
where
Streams<B, Peer>: Send,
impl<B> Sync for SendRequest<B>
where
Streams<B, Peer>: Sync,
impl<B> Unpin for SendRequest<B>
where
Streams<B, Peer>: Unpin,
impl<B> UnsafeUnpin for SendRequest<B>
where
Streams<B, Peer>: UnsafeUnpin,
impl<B> UnwindSafe for SendRequest<B>
where
Streams<B, Peer>: UnwindSafe,
Blanket Implementations
impl<T> Any for SendRequest<B>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for SendRequest<B>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for SendRequest<B>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for SendRequest<B>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for SendRequest<B>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for SendRequest<B>
impl<T> ToOwned for SendRequest<B>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> WithSubscriber for SendRequest<B>
impl<T, U> Into<U> for SendRequest<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 SendRequest<B>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for SendRequest<B>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>