[][src]Struct actix_http::test::TestRequest

pub struct TestRequest(_);

Test Request builder

This example is not tested
use actix_web::test::TestRequest;

fn index(req: &HttpRequest) -> Response {
    if let Some(hdr) = req.headers().get(header::CONTENT_TYPE) {
        Response::Ok().into()
    } else {
        Response::BadRequest().into()
    }
}

fn main() {
    let resp = TestRequest::with_header("content-type", "text/plain")
        .run(&index)
        .unwrap();
    assert_eq!(resp.status(), StatusCode::OK);

    let resp = TestRequest::default().run(&index).unwrap();
    assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}

Methods

impl TestRequest[src]

pub fn with_uri(path: &str) -> TestRequest[src]

Create TestRequest and set request uri

pub fn with_hdr<H: Header>(hdr: H) -> TestRequest[src]

Create TestRequest and set header

pub fn with_header<K, V>(key: K, value: V) -> TestRequest where
    HeaderName: HttpTryFrom<K>,
    V: IntoHeaderValue
[src]

Create TestRequest and set header

pub fn version(&mut self, ver: Version) -> &mut Self[src]

Set HTTP version of this request

pub fn method(&mut self, meth: Method) -> &mut Self[src]

Set HTTP method of this request

pub fn uri(&mut self, path: &str) -> &mut Self[src]

Set HTTP Uri of this request

pub fn set<H: Header>(&mut self, hdr: H) -> &mut Self[src]

Set a header

pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self where
    HeaderName: HttpTryFrom<K>,
    V: IntoHeaderValue
[src]

Set a header

pub fn cookie<'a>(&mut self, cookie: Cookie<'a>) -> &mut Self[src]

Set cookie for this request

pub fn set_payload<B: Into<Bytes>>(&mut self, data: B) -> &mut Self[src]

Set request payload

pub fn take(&mut self) -> TestRequest[src]

pub fn finish(&mut self) -> Request[src]

Complete request creation and generate Request instance

Trait Implementations

impl Default for TestRequest[src]

Auto Trait Implementations

Blanket Implementations

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

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

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.

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.

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

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

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

impl<T> Erased for T

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