context path

This commit is contained in:
Aiden McClelland
2021-07-29 14:47:17 -06:00
parent 38c4ba0dc2
commit 75a8053a3c

View File

@@ -7,19 +7,25 @@ lazy_static! {
} }
pub trait Context { pub trait Context {
fn protocol(&self) -> &str {
"http"
}
fn host(&self) -> Host<&str> { fn host(&self) -> Host<&str> {
Host::Ipv4([127, 0, 0, 1].into()) Host::Ipv4([127, 0, 0, 1].into())
} }
fn port(&self) -> u16 { fn port(&self) -> u16 {
8080 8080
} }
fn protocol(&self) -> &str { fn path(&self) -> &str {
"http" "/"
} }
fn url(&self) -> Url { fn url(&self) -> Url {
format!("{}://{}:{}", self.protocol(), self.host(), self.port()) let mut url: Url = "http://localhost".parse().unwrap();
.parse() url.set_scheme(self.protocol()).expect("protocol");
.unwrap() url.set_host(Some(&self.host().to_string())).expect("host");
url.set_port(Some(self.port())).expect("port");
url.set_path(self.path());
url
} }
fn client(&self) -> &Client { fn client(&self) -> &Client {
&*DEFAULT_CLIENT &*DEFAULT_CLIENT