pub trait RequestExt<B>: Sized {
Show 16 methods
// Required methods
fn json<T: Serialize + ?Sized>(
self,
body: &T,
) -> Result<Request<Full<Bytes>>>;
fn query<Q: Serialize + ?Sized>(self, query: &Q) -> Result<Request<B>>;
fn multipart(
self,
form: Form,
) -> Result<Request<UnsyncBoxBody<Bytes, BodyError>>>;
fn form<T: Serialize + ?Sized>(
self,
form: &T,
) -> Result<Request<Full<Bytes>>>;
fn stream<S: Stream>(self, stream: S) -> Result<Request<StreamBody<S>>>;
fn plain_text(self, body: impl Into<Bytes>) -> Result<Request<Full<Bytes>>>;
fn empty(self) -> Result<Request<Empty<Bytes>>>;
fn collect_into_bytes(
self,
) -> impl Future<Output = Result<Request<Full<Bytes>>>> + Send
where B: Body<Data = Bytes> + Send + 'static,
B::Error: Error + Send + Sync;
fn with_version(self, version: Version) -> Request<B>;
fn with_method(self, method: Method) -> Request<B>;
fn with_header<K>(self, key: K, value: HeaderValue) -> Request<B>
where K: IntoHeaderName;
fn with_headers(self, header_map: HeaderMap) -> Request<B>;
fn send<S, R>(
self,
client: S,
) -> impl Future<Output = Result<S::Response>> + Send
where B: Body<Data = Bytes> + Send + 'static,
B::Error: Error + Send + Sync,
S: Service<Request<ClientBody>, Response = Response<R>> + Send,
R: Body,
<S as Service<Request<ClientBody>>>::Error: Error + Send + Sync + 'static,
<S as Service<Request<ClientBody>>>::Future: Send;
// Provided methods
fn basic_auth<U, P>(self, username: U, password: Option<P>) -> Request<B>
where U: Display,
P: Display,
Self: Sized { ... }
fn bearer_auth<T>(self, token: T) -> Request<B>
where T: Display { ... }
fn send_timeout<S, R>(
self,
client: S,
timeout: Duration,
) -> impl Future<Output = Result<Response<MaybeAbort<R>>>> + Send
where B: Body<Data = Bytes> + Send + 'static,
B::Error: Error + Send + Sync,
S: Service<Request<ClientBody>, Response = Response<R>> + Send,
<S as Service<Request<ClientBody>>>::Error: Error + Send + Sync + 'static,
<S as Service<Request<ClientBody>>>::Future: Send,
R: Body,
Self: Sized { ... }
}
Expand description
Extension trait for http::Request
.
Required Methods§
fn json<T: Serialize + ?Sized>(self, body: &T) -> Result<Request<Full<Bytes>>>
Available on crate feature
json
only.fn query<Q: Serialize + ?Sized>(self, query: &Q) -> Result<Request<B>>
Available on crate feature
query
only.fn multipart( self, form: Form, ) -> Result<Request<UnsyncBoxBody<Bytes, BodyError>>>
Available on crate feature
multipart
only.fn form<T: Serialize + ?Sized>(self, form: &T) -> Result<Request<Full<Bytes>>>
Available on crate feature
form
only.fn stream<S: Stream>(self, stream: S) -> Result<Request<StreamBody<S>>>
fn plain_text(self, body: impl Into<Bytes>) -> Result<Request<Full<Bytes>>>
fn empty(self) -> Result<Request<Empty<Bytes>>>
fn collect_into_bytes( self, ) -> impl Future<Output = Result<Request<Full<Bytes>>>> + Send
fn with_version(self, version: Version) -> Request<B>
fn with_method(self, method: Method) -> Request<B>
fn with_header<K>(self, key: K, value: HeaderValue) -> Request<B>where
K: IntoHeaderName,
fn with_headers(self, header_map: HeaderMap) -> Request<B>
fn send<S, R>( self, client: S, ) -> impl Future<Output = Result<S::Response>> + Send
Provided Methods§
fn basic_auth<U, P>(self, username: U, password: Option<P>) -> Request<B>
Available on crate feature
auth
only.fn bearer_auth<T>(self, token: T) -> Request<B>where
T: Display,
Available on crate feature
auth
only.Sourcefn send_timeout<S, R>(
self,
client: S,
timeout: Duration,
) -> impl Future<Output = Result<Response<MaybeAbort<R>>>> + Send
Available on crate feature rt-tokio
only.
fn send_timeout<S, R>( self, client: S, timeout: Duration, ) -> impl Future<Output = Result<Response<MaybeAbort<R>>>> + Send
rt-tokio
only.Send the request to a service with a timeout layer.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<B> RequestExt<B> for Request<B>where
B: Send,
impl<B> RequestExt<B> for Request<B>where
B: Send,
Source§fn json<T: Serialize + ?Sized>(self, body: &T) -> Result<Request<Full<Bytes>>>
Available on crate feature json
only.
fn json<T: Serialize + ?Sized>(self, body: &T) -> Result<Request<Full<Bytes>>>
json
only.Set the request body as JSON.
Source§fn query<Q: Serialize + ?Sized>(self, query: &Q) -> Result<Request<B>>
Available on crate feature query
only.
fn query<Q: Serialize + ?Sized>(self, query: &Q) -> Result<Request<B>>
query
only.Add query parameters to the request URI.
Source§fn multipart(self, form: Form) -> Result<Request<DynBody>>
Available on crate feature multipart
only.
fn multipart(self, form: Form) -> Result<Request<DynBody>>
multipart
only.Set the request body as multipart form data.
Source§fn form<T: Serialize + ?Sized>(self, form: &T) -> Result<Request<Full<Bytes>>>
Available on crate feature form
only.
fn form<T: Serialize + ?Sized>(self, form: &T) -> Result<Request<Full<Bytes>>>
form
only.Set the request body as form data.
Source§fn plain_text(self, body: impl Into<Bytes>) -> Result<Request<Full<Bytes>>>
fn plain_text(self, body: impl Into<Bytes>) -> Result<Request<Full<Bytes>>>
Set the request body as plain text.
Source§fn stream<S: Stream>(self, stream: S) -> Result<Request<StreamBody<S>>>
fn stream<S: Stream>(self, stream: S) -> Result<Request<StreamBody<S>>>
Set the request body as a stream.
Source§async fn collect_into_bytes(self) -> Result<Request<Full<Bytes>>>
async fn collect_into_bytes(self) -> Result<Request<Full<Bytes>>>
Collect the request body stream into bytes. This is useful when you want to clone the request.
Source§fn with_version(self, version: Version) -> Request<B>
fn with_version(self, version: Version) -> Request<B>
Set the request HTTP version.
Source§fn with_method(self, method: Method) -> Request<B>
fn with_method(self, method: Method) -> Request<B>
Set the request method.
Source§fn with_header<K>(self, key: K, value: HeaderValue) -> Request<B>where
K: IntoHeaderName,
fn with_header<K>(self, key: K, value: HeaderValue) -> Request<B>where
K: IntoHeaderName,
Set a request header.
Source§fn with_headers(self, header_map: HeaderMap) -> Request<B>
fn with_headers(self, header_map: HeaderMap) -> Request<B>
Extend multiple request headers.