Struct tiny_http::TestRequest
source · [−]pub struct TestRequest { /* private fields */ }
Expand description
A simpler version of Request
that is useful for testing. No data actually goes anywhere.
By default, TestRequest
pretends to be an insecure GET request for the server root (/
)
with no headers. To create a TestRequest
with different parameters, use the builder pattern:
let request = TestRequest::new()
.with_method(Method::Post)
.with_path("/api/widgets")
.with_body("42");
Then, convert the TestRequest
into a real Request
and pass it to the server under test:
let response = server.handle_request(request.into());
assert_eq!(response.status_code(), StatusCode(200));
Implementations
sourceimpl TestRequest
impl TestRequest
pub fn new() -> Self
pub fn with_body(self, body: &'static str) -> Self
pub fn with_remote_addr(self, remote_addr: SocketAddr) -> Self
pub fn with_https(self) -> Self
pub fn with_method(self, method: Method) -> Self
pub fn with_path(self, path: &'static str) -> Self
pub fn with_http_version(self, version: HTTPVersion) -> Self
pub fn with_header(self, header: Header) -> Self
Trait Implementations
sourceimpl Default for TestRequest
impl Default for TestRequest
sourceimpl From<TestRequest> for Request
impl From<TestRequest> for Request
sourcefn from(mock: TestRequest) -> Request
fn from(mock: TestRequest) -> Request
Performs the conversion.
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 · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more