use super::Host;
impl Host for http_0_2::Uri {
fn hostname(&self) -> &str {
self.host().unwrap_or("")
}
fn port(&self) -> Option<u16> {
match self.port_u16() {
Some(port) => Some(port),
None => scheme_to_port(self.scheme_str()),
}
}
}
impl Host for http_1::Uri {
fn hostname(&self) -> &str {
self.host().unwrap_or("")
}
fn port(&self) -> Option<u16> {
match self.port_u16() {
Some(port) => Some(port),
None => scheme_to_port(self.scheme_str()),
}
}
}
fn scheme_to_port(scheme: Option<&str>) -> Option<u16> {
match scheme {
Some("http") => Some(80),
Some("https") => Some(443),
Some("ws") => Some(80),
Some("wss") => Some(443),
Some("amqp") => Some(5672),
Some("amqps") => Some(5671),
Some("mqtt") => Some(1883),
Some("mqtts") => Some(8883),
Some("ftp") => Some(21),
Some("ftps") => Some(990),
Some("redis") => Some(6379),
Some("mysql") => Some(3306),
Some("postgres") => Some(5432),
_ => None,
}
}