pub struct TestRequest { /* private fields */ }Expand description
A fluent request builder used only in tests; invalid requests panic clearly.
Implementations§
Source§impl TestRequest
impl TestRequest
Sourcepub fn peer_addr(self, peer: SocketAddr) -> Self
pub fn peer_addr(self, peer: SocketAddr) -> Self
Supply a simulated socket peer, independent of forwarded headers.
Sourcepub fn without_peer(self) -> Self
pub fn without_peer(self) -> Self
Omit socket metadata to test fail-closed custom-server behavior.
Sourcepub fn json(self, value: impl Serialize) -> Self
pub fn json(self, value: impl Serialize) -> Self
Serialize a JSON body and set the content type.
Sourcepub fn header(self, name: HeaderName, value: HeaderValue) -> Self
pub fn header(self, name: HeaderName, value: HeaderValue) -> Self
Set a header, for example authorization or content type.
Set a session cookie without depending on an application’s user model. Use TestResponse::cookie to reuse a server-issued cookie.
Sourcepub fn body(self, body: impl Into<Body>) -> Self
pub fn body(self, body: impl Into<Body>) -> Self
Set a raw body, useful for malformed request tests.
Sourcepub async fn send(self) -> TestResponse
pub async fn send(self) -> TestResponse
Execute the request directly against the service.
Auto Trait Implementations§
impl !Freeze for TestRequest
impl !RefUnwindSafe for TestRequest
impl !Sync for TestRequest
impl !UnwindSafe for TestRequest
impl Send for TestRequest
impl Unpin for TestRequest
impl UnsafeUnpin for TestRequest
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
Mutably borrows from an owned value. Read more