[−][src]Struct http_test_server::TestServer
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
impl RefUnwindSafe for TestServer
impl Send for TestServer
impl Sync for TestServer
impl Unpin for TestServer
impl UnwindSafe for TestServer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,