Struct http_test_server::TestServer [−][src]
pub struct TestServer { /* fields omitted */ }
Controls the listener life cycle and creates new resources
Methods
impl TestServer
[src]
impl TestServer
pub fn new() -> Result<TestServer, Error>
[src]
pub fn new() -> Result<TestServer, Error>
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]
pub fn new_with_port(port: u16) -> Result<TestServer, Error>
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]
pub fn port(&self) -> u16
Returns associated port number.
let server = TestServer::new().unwrap(); assert!(server.port() > 0);
pub fn close(&self)
[src]
pub fn close(&self)
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]
pub fn create_resource(&self, uri: &str) -> Resource
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]
pub fn requests(&self) -> Receiver<Request>
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]
impl Drop for TestServer
Auto Trait Implementations
impl Send for TestServer
impl Send for TestServer
impl Sync for TestServer
impl Sync for TestServer