pub struct TestRequest<'a> { /* private fields */ }Expand description
A request being built: app.request().header("accept", "application/json").get(..).
Implementations§
Source§impl TestRequest<'_>
impl TestRequest<'_>
Sourcepub fn header(self, name: &str, value: &str) -> Self
pub fn header(self, name: &str, value: &str) -> Self
Adds a request header; may be called several times.
Sourcepub fn without_csrf(self) -> Self
pub fn without_csrf(self) -> Self
Sends no CSRF token, to test that a form is protected.
Sourcepub async fn get(self, uri: &str) -> TestResponse
pub async fn get(self, uri: &str) -> TestResponse
Sends it as a GET.
Sourcepub async fn post(self, uri: &str, form: &[(&str, &str)]) -> TestResponse
pub async fn post(self, uri: &str, form: &[(&str, &str)]) -> TestResponse
Sends it as a form post (urlencoded), with the CSRF token unless without_csrf.
Sourcepub async fn put(self, uri: &str, form: &[(&str, &str)]) -> TestResponse
pub async fn put(self, uri: &str, form: &[(&str, &str)]) -> TestResponse
Sends it as a form PUT (urlencoded), with the CSRF token unless without_csrf.
Sourcepub async fn patch(self, uri: &str, form: &[(&str, &str)]) -> TestResponse
pub async fn patch(self, uri: &str, form: &[(&str, &str)]) -> TestResponse
Sends it as a form PATCH (urlencoded), with the CSRF token unless without_csrf.
Sourcepub async fn delete(self, uri: &str) -> TestResponse
pub async fn delete(self, uri: &str) -> TestResponse
Sends it as a DELETE, with the CSRF token unless without_csrf.
Sourcepub async fn post_multipart(
self,
uri: &str,
fields: &[(&str, &str)],
files: &[(&str, &str, &[u8])],
) -> TestResponse
pub async fn post_multipart( self, uri: &str, fields: &[(&str, &str)], files: &[(&str, &str, &[u8])], ) -> TestResponse
A multipart form, as a browser sends one with a file input:
post_multipart("/photos", &[("title", "Coffee")], &[("photo", "coffee.png", &bytes)]).
Sourcepub async fn post_body(
self,
uri: &str,
content_type: &str,
body: impl Into<Vec<u8>>,
) -> TestResponse
pub async fn post_body( self, uri: &str, content_type: &str, body: impl Into<Vec<u8>>, ) -> TestResponse
A POST with exactly these bytes, e.g. a webhook whose signature covers the raw body.
Sourcepub async fn post_json(self, uri: &str, body: &impl Serialize) -> TestResponse
pub async fn post_json(self, uri: &str, body: &impl Serialize) -> TestResponse
Sends body as a JSON POST, with the CSRF token unless without_csrf.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for TestRequest<'a>
impl<'a> !UnwindSafe for TestRequest<'a>
impl<'a> Freeze for TestRequest<'a>
impl<'a> Send for TestRequest<'a>
impl<'a> Sync for TestRequest<'a>
impl<'a> Unpin for TestRequest<'a>
impl<'a> UnsafeUnpin for TestRequest<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more