Struct http_test_server::TestServer[][src]

pub struct TestServer { /* fields omitted */ }

Controls the listener life cycle and creates new resources

Methods

impl TestServer
[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();

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();

Returns associated port number.

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

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

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();

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");

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]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl Send for TestServer

impl Sync for TestServer