pub struct RequestBuilder { /* private fields */ }
Expand description
A request builder for testing filters.
See module documentation for an overview.
Implementations
sourceimpl RequestBuilder
impl RequestBuilder
sourcepub fn method(self, method: &str) -> RequestBuilder
pub fn method(self, method: &str) -> RequestBuilder
sourcepub fn path(self, p: &str) -> RequestBuilder
pub fn path(self, p: &str) -> RequestBuilder
sourcepub fn header<K, V>(self, key: K, value: V) -> RequestBuilder where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
pub fn header<K, V>(self, key: K, value: V) -> RequestBuilder where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
sourcepub fn remote_addr(self, addr: SocketAddr) -> RequestBuilder
pub fn remote_addr(self, addr: SocketAddr) -> RequestBuilder
Set the remote address of this request
Default is no remote address.
Example
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
let req = warp::test::request()
.remote_addr(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080));
sourcepub fn extension<T>(self, ext: T) -> RequestBuilder where
T: 'static + Send + Sync,
pub fn extension<T>(self, ext: T) -> RequestBuilder where
T: 'static + Send + Sync,
Add a type to the request’s http::Extensions
.
sourcepub fn body(self, body: impl AsRef<[u8]>) -> RequestBuilder
pub fn body(self, body: impl AsRef<[u8]>) -> RequestBuilder
Set the bytes of this request body.
Default is an empty body.
Example
let req = warp::test::request()
.body("foo=bar&baz=quux");
sourcepub fn json(self, val: &impl Serialize) -> RequestBuilder
pub fn json(self, val: &impl Serialize) -> RequestBuilder
Set the bytes of this request body by serializing a value into JSON.
Example
let req = warp::test::request()
.json(&true);
sourcepub async fn filter<F>(
self,
f: &'_ F
) -> Result<<<F as FilterBase>::Extract as OneOrTuple>::Output, <F as FilterBase>::Error> where
F: Filter,
<F as FilterBase>::Future: 'static,
<F as FilterBase>::Future: Send,
<F as FilterBase>::Extract: 'static,
<F as FilterBase>::Extract: OneOrTuple,
<F as FilterBase>::Extract: Send,
<F as FilterBase>::Error: 'static,
<F as FilterBase>::Error: Send,
pub async fn filter<F>(
self,
f: &'_ F
) -> Result<<<F as FilterBase>::Extract as OneOrTuple>::Output, <F as FilterBase>::Error> where
F: Filter,
<F as FilterBase>::Future: 'static,
<F as FilterBase>::Future: Send,
<F as FilterBase>::Extract: 'static,
<F as FilterBase>::Extract: OneOrTuple,
<F as FilterBase>::Extract: Send,
<F as FilterBase>::Error: 'static,
<F as FilterBase>::Error: Send,
Tries to apply the Filter
on this request.
Example
async {
let param = warp::path::param::<u32>();
let ex = warp::test::request()
.path("/41")
.filter(¶m)
.await
.unwrap();
assert_eq!(ex, 41);
assert!(
warp::test::request()
.path("/foo")
.filter(¶m)
.await
.is_err()
);
};
sourcepub async fn matches<F>(self, f: &'_ F) -> bool where
F: Filter,
<F as FilterBase>::Future: 'static,
<F as FilterBase>::Future: Send,
<F as FilterBase>::Extract: 'static,
<F as FilterBase>::Extract: Send,
<F as FilterBase>::Error: 'static,
<F as FilterBase>::Error: Send,
pub async fn matches<F>(self, f: &'_ F) -> bool where
F: Filter,
<F as FilterBase>::Future: 'static,
<F as FilterBase>::Future: Send,
<F as FilterBase>::Extract: 'static,
<F as FilterBase>::Extract: Send,
<F as FilterBase>::Error: 'static,
<F as FilterBase>::Error: Send,
Returns whether the Filter
matches this request, or rejects it.
Example
async {
let get = warp::get();
let post = warp::post();
assert!(
warp::test::request()
.method("GET")
.matches(&get)
.await
);
assert!(
!warp::test::request()
.method("GET")
.matches(&post)
.await
);
};
sourcepub async fn reply<F>(self, f: &'_ F) -> Response<Bytes> where
F: 'static + Filter,
<F as FilterBase>::Extract: Reply,
<F as FilterBase>::Extract: Send,
<F as FilterBase>::Error: IsReject,
<F as FilterBase>::Error: Send,
pub async fn reply<F>(self, f: &'_ F) -> Response<Bytes> where
F: 'static + Filter,
<F as FilterBase>::Extract: Reply,
<F as FilterBase>::Extract: Send,
<F as FilterBase>::Error: IsReject,
<F as FilterBase>::Error: Send,
Returns Response
provided by applying the Filter
.
This requires that the supplied Filter
return a Reply
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for RequestBuilder
impl Send for RequestBuilder
impl Sync for RequestBuilder
impl Unpin for RequestBuilder
impl !UnwindSafe for RequestBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
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>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more