Struct actix_http::test::TestRequest
source · [−]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
pub fn with_header<K, V>(key: K, value: V) -> TestRequest where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
pub fn with_header<K, V>(key: K, value: V) -> TestRequest where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
Create TestRequest and set header
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
Set a header
Set cookie for this request
Set request payload
Trait Implementations
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl !RefUnwindSafe for TestRequest
impl !Send for TestRequest
impl !Sync for TestRequest
impl Unpin for TestRequest
impl !UnwindSafe for TestRequest
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
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