1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#[cfg(feature = "use_hyper")] extern crate hyper; #[cfg(feature = "use_hyper")] extern crate url as servo_url; pub mod server; pub mod client; pub mod mock; pub mod url; #[cfg(feature = "use_hyper")] pub mod mockable_hyper; pub mod mockable_tcp_stream; pub type Url<'a> = url::Url<'a>; pub type Mock = mock::Mock; pub fn mock(method: &str, path: &str) -> Mock { Mock::new(method, path) } #[cfg(test)] #[cfg(feature = "mock_hyper")] mod mock_hyper_tests { use hyper::Client; use hyper::header::Connection; use server; use url::Url; use std::io::Read; #[test] fn test_proxying() { super::start(); let client = Client::new(); let mut res = client.get(Url("http://www.example.com")) .header(Connection::close()) .send() .unwrap(); let mut body = String::new(); res.read_to_string(&mut body).unwrap(); assert_eq!(body, "Hello world"); } } #[cfg(test)] #[cfg(feature = "mock_tcp_stream")] mod mock_tcp_stream_tests { use MockBuilder; use super::mock; #[test] fn test_mock() { let mock = mock("GET /"); assert_eq!("GET /", mock.request_line); } }