[−][src]Struct warp::test::RequestBuilder
A request builder for testing filters.
See module documentation for an overview.
Methods
impl RequestBuilder
[src]
pub fn method(self, method: &str) -> Self
[src]
Sets the method of this builder.
The default if not set is GET
.
Example
let req = warp::test::request() .method("POST");
Panic
This panics if the passed string is not able to be parsed as a valid
Method
.
pub fn path(self, p: &str) -> Self
[src]
Sets the request path of this builder.
The default is not set is /
.
Example
let req = warp::test::request() .path("/todos/33");
Panic
This panics if the passed string is not able to be parsed as a valid
Uri
.
pub fn header<K, V>(self, key: K, value: V) -> Self where
HeaderName: HttpTryFrom<K>,
HeaderValue: HttpTryFrom<V>,
[src]
HeaderName: HttpTryFrom<K>,
HeaderValue: HttpTryFrom<V>,
Set a header for this request.
Example
let req = warp::test::request() .header("accept", "application/json");
Panic
This panics if the passed strings are not able to be parsed as a valid
HeaderName
and HeaderValue
.
pub fn body(
self,
body: impl AsRef<[u8]>
) -> Self
[src]
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");
pub fn json(
self,
val: &impl Serialize
) -> Self
[src]
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);
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,
[src]
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() );
pub fn matches<F>(self, f: &F) -> bool where
F: Filter,
F::Future: Send + 'static,
F::Extract: Send + 'static,
F::Error: Send + 'static,
[src]
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) );
pub fn reply<F>(self, f: &F) -> Response<Bytes> where
F: Filter + 'static,
F::Extract: Reply + Send,
F::Error: Reject + Send,
[src]
F: Filter + 'static,
F::Extract: Reply + Send,
F::Error: Reject + Send,
Returns Response
provided by applying the Filter
.
This requires that the supplied Filter
return a Reply
.
Trait Implementations
Auto Trait Implementations
impl Send for RequestBuilder
impl !Sync for RequestBuilder
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Same for T
type Output = T
Should always be Self