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::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
sourceimpl TestRequest
impl TestRequest
sourcepub fn with_uri(path: &str) -> TestRequest
pub fn with_uri(path: &str) -> TestRequest
Create a default TestRequest and then set its URI.
sourcepub fn insert_header(&mut self, header: impl TryIntoHeaderPair) -> &mut Self
pub fn insert_header(&mut self, header: impl TryIntoHeaderPair) -> &mut Self
Insert a header, replacing any that were set with an equivalent field name.
sourcepub fn append_header(&mut self, header: impl TryIntoHeaderPair) -> &mut Self
pub fn append_header(&mut self, header: impl TryIntoHeaderPair) -> &mut Self
Append a header, keeping any that were set with an equivalent field name.
sourcepub fn set_payload<B: Into<Bytes>>(&mut self, data: B) -> &mut Self
pub fn set_payload<B: Into<Bytes>>(&mut self, data: B) -> &mut Self
Set request payload.
pub fn take(&mut self) -> TestRequest
Trait Implementations
sourceimpl Default for TestRequest
impl Default for TestRequest
sourcefn default() -> TestRequest
fn default() -> TestRequest
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more