[][src]Struct http_test_server::TestServer

pub struct TestServer { /* fields omitted */ }

Controls the listener life cycle and creates new resources

Methods

impl TestServer[src]

pub fn new() -> Result<TestServer, Error>[src]

Creates a listener that is bounded to a free port in localhost. Listener is closed when the value is dropped.

Any request for non-defined resources will return 404.

let server = TestServer::new().unwrap();

pub fn new_with_port(port: u16) -> Result<TestServer, Error>[src]

Same behaviour as new, but tries to bound to given port instead of looking for a free one.

let server = TestServer::new_with_port(8080).unwrap();

pub fn port(&self) -> u16[src]

Returns associated port number.

let server = TestServer::new().unwrap();

assert!(server.port() > 0);

pub fn close(&self)[src]

Closes listener. Server stops receiving connections. Do nothing if listener is already closed.

In most the cases this method is not required as the listener is automatically closed when the value is dropped.

let server = TestServer::new().unwrap();

server.close();

pub fn create_resource(&self, uri: &str) -> Resource[src]

Creates a new resource. By default resources answer "200 Ok".

Check Resource for all possible configurations.

let server = TestServer::new().unwrap();
let resource = server.create_resource("/user/settings");

pub fn requests(&self) -> Receiver<Request>[src]

Retrieves information on new requests.

let server = TestServer::new().unwrap();

for request in server.requests().iter() {
    assert_eq!(request.url, "/endpoint");
    assert_eq!(request.method, "GET");
    assert_eq!(request.headers.get("Content-Type").unwrap(), "text");
}

Trait Implementations

impl Drop for TestServer[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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.

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.