tiny_http

Struct 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§

Source§

impl TestRequest

Source

pub fn new() -> Self

Source

pub fn with_body(self, body: &'static str) -> Self

Source

pub fn with_remote_addr(self, remote_addr: SocketAddr) -> Self

Source

pub fn with_https(self) -> Self

Source

pub fn with_method(self, method: Method) -> Self

Source

pub fn with_path(self, path: &str) -> Self

Source

pub fn with_http_version(self, version: HTTPVersion) -> Self

Source

pub fn with_header(self, header: Header) -> Self

Trait Implementations§

Source§

impl Default for TestRequest

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<TestRequest> for Request

Source§

fn from(mock: TestRequest) -> Request

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.