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

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 panics is handler returns actor or async result.

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

This method panics is handler returns actor.

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>