logo
pub struct TestRequest(_);
Expand description

Test Request builder

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

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

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 cookie for this request

Set request payload

Complete request creation and generate Request instance

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

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more