Struct choices::warp::test::RequestBuilder[][src]

#[must_use = "RequestBuilder does nothing on its own"]
pub struct RequestBuilder { /* fields omitted */ }

A request builder for testing filters.

See module documentation for an overview.

Implementations

impl RequestBuilder[src]

pub fn method(self, method: &str) -> RequestBuilder[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) -> RequestBuilder[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) -> RequestBuilder where
    HeaderName: TryFrom<K>,
    HeaderValue: TryFrom<V>, 
[src]

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 remote_addr(self, addr: SocketAddr) -> RequestBuilder[src]

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

pub fn extension<T>(self, ext: T) -> RequestBuilder where
    T: Send + Sync + 'static, 
[src]

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

pub fn body(self, body: impl AsRef<[u8]>) -> RequestBuilder[src]

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) -> RequestBuilder[src]

Set the bytes of this request body by serializing a value into JSON.

Example

let req = warp::test::request()
    .json(&true);

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: Send,
    <F as FilterBase>::Future: 'static,
    <F as FilterBase>::Extract: OneOrTuple,
    <F as FilterBase>::Extract: Send,
    <F as FilterBase>::Extract: 'static,
    <F as FilterBase>::Error: Send,
    <F as FilterBase>::Error: 'static, 
[src]

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()
    );
};

pub async fn matches<F>(self, f: &'_ F) -> bool where
    F: Filter,
    <F as FilterBase>::Future: Send,
    <F as FilterBase>::Future: 'static,
    <F as FilterBase>::Extract: Send,
    <F as FilterBase>::Extract: 'static,
    <F as FilterBase>::Error: Send,
    <F as FilterBase>::Error: 'static, 
[src]

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

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

Returns Response provided by applying the Filter.

This requires that the supplied Filter return a Reply.

Trait Implementations

impl Debug for RequestBuilder[src]

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T

Notable traits for &'_ mut F

impl<'_, F> Future for &'_ mut F where
    F: Future + Unpin + ?Sized
type Output = <F as Future>::Output;
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

Notable traits for &'_ mut F

impl<'_, F> Future for &'_ mut F where
    F: Future + Unpin + ?Sized
type Output = <F as Future>::Output;
[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

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;
[src]

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

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;
[src]

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

impl<T> Instrument for T[src]

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;
[src]

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

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;
[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

pub fn vzip(self) -> V