Struct tiny_http::TestRequest[][src]

pub struct TestRequest { /* fields omitted */ }
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

impl TestRequest[src]

pub fn new() -> Self[src]

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

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

pub fn with_https(self) -> Self[src]

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

pub fn with_path(self, path: &'static str) -> Self[src]

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

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

Trait Implementations

impl Default for TestRequest[src]

fn default() -> Self[src]

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

impl From<TestRequest> for Request[src]

fn from(mock: TestRequest) -> Request[src]

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.