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

Create TestRequest and set request uri

Create TestRequest and set header

Create TestRequest and set header

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

Start HttpRequest build process with application state

Set HTTP version of this request

Set HTTP method of this request

Set HTTP Uri of this request

Set a header

Set a header

Set request path pattern parameter

Set request payload

Set request's prefix

Complete request creation and generate HttpRequest instance

Complete request creation and generate server Request instance

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

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

This method panics is handler returns actor.

This method generates HttpRequest instance and executes handler

This method generates HttpRequest instance and executes handler

Trait Implementations

impl Default for TestRequest<()>
[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl<S> !Send for TestRequest<S>

impl<S> !Sync for TestRequest<S>

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

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

Performs the conversion.

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

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

Immutably borrows from an owned value. Read more

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

Mutably borrows from an owned value. Read more

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

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

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> Erased for T