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§

source§

impl RequestBuilder

source

pub fn method(self, method: &str) -> Self

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.

source

pub fn path(self, p: &str) -> Self

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.

source

pub fn header<K, V>(self, key: K, value: V) -> Self

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.

source

pub fn remote_addr(self, addr: SocketAddr) -> Self

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));
source

pub fn extension<T>(self, ext: T) -> Self
where T: Send + Sync + 'static,

Add a type to the request’s http::Extensions.

source

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");
source

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);
source

pub async 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
async {
    let param = warp::path::param::<u32>();

    let ex = warp::test::request()
        .path("/41")
        .filter(&param)
        .await
        .unwrap();

    assert_eq!(ex, 41);

    assert!(
        warp::test::request()
            .path("/foo")
            .filter(&param)
            .await
            .is_err()
    );
};
source

pub async fn matches<F>(self, f: &F) -> bool
where 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
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
    );
};
source

pub async fn reply<F>(self, f: &F) -> Response<Bytes>
where F: Filter + 'static, F::Extract: Reply + Send, F::Error: IsReject + Send,

Returns Response provided by applying the Filter.

This requires that the supplied Filter return a Reply.

Trait Implementations§

source§

impl Debug for RequestBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more