Struct gotham::test::AsyncTestRequestBuilder
source · [−]pub struct AsyncTestRequestBuilder<'client, C: Connect> { /* private fields */ }
Expand description
Builder for a request made with an AsyncTestClient
.
Once a request is fully built, it can be performed using the [perform
] method.
Implementations
sourceimpl<'client, C: Connect + Clone + Send + Sync + 'static> AsyncTestRequestBuilder<'client, C>
impl<'client, C: Connect + Clone + Send + Sync + 'static> AsyncTestRequestBuilder<'client, C>
sourcepub async fn perform(self) -> Result<AsyncTestResponse>
pub async fn perform(self) -> Result<AsyncTestResponse>
Perform the built request.
sourcepub fn mime(self, mime: Mime) -> Self
pub fn mime(self, mime: Mime) -> Self
Convenience method to append a content-type
header for the given MIME type.
sourcepub fn body<B: Into<Body>>(self, body: B) -> Self
pub fn body<B: Into<Body>>(self, body: B) -> Self
Set a Body for this request. See http::request::Builder::body
.
Other than the http::request::Builder::body
it doesn’t finish building
the request though, instead if called multiple times, only the last one is kept.
Defaults to Body::empty
if never called.
sourcepub fn extension<T>(self, extension: T) -> Self where
T: Any + Send + Sync + 'static,
pub fn extension<T>(self, extension: T) -> Self where
T: Any + Send + Sync + 'static,
Add a custom value to this request. See http::request::Builder::extension
sourcepub fn header<K, V>(self, key: K, value: V) -> Self where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
pub fn header<K, V>(self, key: K, value: V) -> Self where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Add a header to this request. See http::request::Builder::header
sourcepub fn method<M>(self, method: M) -> Self where
Method: TryFrom<M>,
<Method as TryFrom<M>>::Error: Into<Error>,
pub fn method<M>(self, method: M) -> Self where
Method: TryFrom<M>,
<Method as TryFrom<M>>::Error: Into<Error>,
Set the method of this request. See http::request::Builder::method
sourcepub fn uri<U>(self, uri: U) -> Self where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<Error>,
pub fn uri<U>(self, uri: U) -> Self where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<Error>,
Set the Uri
of this request. See http::request::Builder::uri
sourcepub fn version(self, version: Version) -> Self
pub fn version(self, version: Version) -> Self
Set the Version
(HTTP Version) of this Request. http::request::Builder::version
.
Methods from Deref<Target = Builder>
sourcepub fn method_ref(&self) -> Option<&Method>
pub fn method_ref(&self) -> Option<&Method>
Get the HTTP Method for this request.
By default this is GET
. If builder has error, returns None.
Examples
let mut req = Request::builder();
assert_eq!(req.method_ref(),Some(&Method::GET));
req = req.method("POST");
assert_eq!(req.method_ref(),Some(&Method::POST));
sourcepub fn uri_ref(&self) -> Option<&Uri>
pub fn uri_ref(&self) -> Option<&Uri>
Get the URI for this request
By default this is /
.
Examples
let mut req = Request::builder();
assert_eq!(req.uri_ref().unwrap(), "/" );
req = req.uri("https://www.rust-lang.org/");
assert_eq!(req.uri_ref().unwrap(), "https://www.rust-lang.org/" );
sourcepub fn version_ref(&self) -> Option<&Version>
pub fn version_ref(&self) -> Option<&Version>
Get the HTTP version for this request
By default this is HTTP/1.1.
Examples
let mut req = Request::builder();
assert_eq!(req.version_ref().unwrap(), &Version::HTTP_11 );
req = req.version(Version::HTTP_2);
assert_eq!(req.version_ref().unwrap(), &Version::HTTP_2 );
sourcepub fn headers_ref(&self) -> Option<&HeaderMap<HeaderValue>>
pub fn headers_ref(&self) -> Option<&HeaderMap<HeaderValue>>
Get header on this request builder. when builder has error returns None
Example
let req = Request::builder()
.header("Accept", "text/html")
.header("X-Custom-Foo", "bar");
let headers = req.headers_ref().unwrap();
assert_eq!( headers["Accept"], "text/html" );
assert_eq!( headers["X-Custom-Foo"], "bar" );
sourcepub fn headers_mut(&mut self) -> Option<&mut HeaderMap<HeaderValue>>
pub fn headers_mut(&mut self) -> Option<&mut HeaderMap<HeaderValue>>
Get headers on this request builder.
When builder has error returns None.
Example
let mut req = Request::builder();
{
let headers = req.headers_mut().unwrap();
headers.insert("Accept", HeaderValue::from_static("text/html"));
headers.insert("X-Custom-Foo", HeaderValue::from_static("bar"));
}
let headers = req.headers_ref().unwrap();
assert_eq!( headers["Accept"], "text/html" );
assert_eq!( headers["X-Custom-Foo"], "bar" );
sourcepub fn extensions_ref(&self) -> Option<&Extensions>
pub fn extensions_ref(&self) -> Option<&Extensions>
Get a reference to the extensions for this request builder.
If the builder has an error, this returns None
.
Example
let req = Request::builder().extension("My Extension").extension(5u32);
let extensions = req.extensions_ref().unwrap();
assert_eq!(extensions.get::<&'static str>(), Some(&"My Extension"));
assert_eq!(extensions.get::<u32>(), Some(&5u32));
sourcepub fn extensions_mut(&mut self) -> Option<&mut Extensions>
pub fn extensions_mut(&mut self) -> Option<&mut Extensions>
Get a mutable reference to the extensions for this request builder.
If the builder has an error, this returns None
.
Example
let mut req = Request::builder().extension("My Extension");
let mut extensions = req.extensions_mut().unwrap();
assert_eq!(extensions.get::<&'static str>(), Some(&"My Extension"));
extensions.insert(5u32);
assert_eq!(extensions.get::<u32>(), Some(&5u32));
Trait Implementations
sourceimpl<'client, C: Connect> Deref for AsyncTestRequestBuilder<'client, C>
impl<'client, C: Connect> Deref for AsyncTestRequestBuilder<'client, C>
Auto Trait Implementations
impl<'client, C> !RefUnwindSafe for AsyncTestRequestBuilder<'client, C>
impl<'client, C> Send for AsyncTestRequestBuilder<'client, C> where
C: Sync,
impl<'client, C> Sync for AsyncTestRequestBuilder<'client, C> where
C: Sync,
impl<'client, C> Unpin for AsyncTestRequestBuilder<'client, C>
impl<'client, C> !UnwindSafe for AsyncTestRequestBuilder<'client, C>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more