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::default().insert_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 a default TestRequest and then set its URI.

Set HTTP version of this request.

Set HTTP method of this request.

Set URI of this request.

Panics

If provided URI is invalid.

Insert a header, replacing any that were set with an equivalent field name.

Append a header, keeping any that were set with an equivalent field name.

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

Returns the argument unchanged.

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

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.

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