Struct warp::test::RequestBuilder
source · 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 header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: HttpTryFrom<K>,
HeaderValue: HttpTryFrom<V>,
pub fn header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: HttpTryFrom<K>,
HeaderValue: HttpTryFrom<V>,
sourcepub fn body(self, body: impl AsRef<[u8]>) -> Self
pub fn body(self, body: impl AsRef<[u8]>) -> Self
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) -> Self
pub fn json(self, val: &impl Serialize) -> Self
Set the bytes of this request body by serializing a value into JSON.
Example
let req = warp::test::request()
.json(&true);
sourcepub fn filter<F>(
self,
f: &F
) -> Result<<F::Extract as OneOrTuple>::Output, F::Error>where
F: Filter,
F::Future: Send + 'static,
F::Extract: OneOrTuple + Send + 'static,
F::Error: Send + 'static,
pub fn filter<F>(
self,
f: &F
) -> Result<<F::Extract as OneOrTuple>::Output, F::Error>where
F: Filter,
F::Future: Send + 'static,
F::Extract: OneOrTuple + Send + 'static,
F::Error: Send + 'static,
Tries to apply the Filter
on this request.
Example
let param = warp::path::param::<u32>();
let ex = warp::test::request()
.path("/41")
.filter(¶m)
.unwrap();
assert_eq!(ex, 41);
assert!(
warp::test::request()
.path("/foo")
.filter(¶m)
.is_err()
);
sourcepub fn matches<F>(self, f: &F) -> boolwhere
F: Filter,
F::Future: Send + 'static,
F::Extract: Send + 'static,
F::Error: Send + 'static,
pub fn matches<F>(self, f: &F) -> boolwhere
F: Filter,
F::Future: Send + 'static,
F::Extract: Send + 'static,
F::Error: Send + 'static,
Returns whether the Filter
matches this request, or rejects it.
Example
let get = warp::get2();
let post = warp::post2();
assert!(
warp::test::request()
.method("GET")
.matches(&get)
);
assert!(
!warp::test::request()
.method("GET")
.matches(&post)
);
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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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