[][src]Struct actix_web::test::TestRequest

pub struct TestRequest<S> { /* fields omitted */ }

Test HttpRequest builder

use actix_web::test::TestRequest;

fn index(req: &HttpRequest) -> HttpResponse {
    if let Some(hdr) = req.headers().get(header::CONTENT_TYPE) {
        HttpResponse::Ok().into()
    } else {
        HttpResponse::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

Create TestRequest and set request cookie

impl<S: 'static> TestRequest<S>[src]

pub fn with_state(state: S) -> TestRequest<S>[src]

Start HttpRequest build process with application state

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

Set HTTP version of this request

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

Set HTTP method of this request

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

Set HTTP Uri of this request

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

set cookie of this request

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

Set a header

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

Set a header

pub fn param(self, name: &'static str, value: &'static str) -> Self[src]

Set request path pattern parameter

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

Set request payload

pub fn prefix(self, prefix: u16) -> Self[src]

Set request's prefix

pub fn finish(self) -> HttpRequest<S>[src]

Complete request creation and generate HttpRequest instance

pub fn request(self) -> Request[src]

Complete request creation and generate server Request instance

pub fn run<H: Handler<S>>(self, h: &H) -> Result<HttpResponse, Error>[src]

This method generates HttpRequest instance and runs handler with generated request.

pub fn run_async<H, R, F, E>(self, h: H) -> Result<HttpResponse, E> where
    H: Fn(HttpRequest<S>) -> F + 'static,
    F: Future<Item = R, Error = E> + 'static,
    R: Responder<Error = E> + 'static,
    E: Into<Error> + 'static, 
[src]

This method generates HttpRequest instance and runs handler with generated request.

This method panics is handler returns actor.

pub fn run_async_result<F, R, I, E>(self, f: F) -> Result<I, E> where
    F: FnOnce(&HttpRequest<S>) -> R,
    R: Into<AsyncResult<I, E>>, 
[src]

This method generates HttpRequest instance and executes handler

pub fn execute<F, R>(self, f: F) -> Result<HttpResponse, Error> where
    F: FnOnce(&HttpRequest<S>) -> R,
    R: Responder + 'static, 
[src]

This method generates HttpRequest instance and executes handler

Trait Implementations

impl Default for TestRequest<()>[src]

Auto Trait Implementations

impl<S> !Send for TestRequest<S>

impl<S> !Sync for TestRequest<S>

Blanket Implementations

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

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

impl<T, U> TryInto 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> Erased for T