Struct actix_web::test::TestRequest

source ·
pub struct TestRequest<S> { /* private fields */ }
Expand description

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

Implementations

Create TestRequest and set request uri

Create TestRequest and set header

Create TestRequest and set header

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

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.