use super::Request;
impl Request {
pub fn is_secure(&self) -> bool {
if self.is_secure {
return true;
}
if self.is_from_trusted_proxy()
&& let Some(proto) = self
.headers
.get("x-forwarded-proto")
.and_then(|h| h.to_str().ok())
{
return proto.eq_ignore_ascii_case("https");
}
false
}
pub fn scheme(&self) -> &str {
if self.is_secure() { "https" } else { "http" }
}
pub fn build_absolute_uri(&self, path: Option<&str>) -> String {
let scheme = self.scheme();
let host = self.get_host().unwrap_or_else(|| "localhost".to_string());
let path = path.unwrap_or_else(|| self.path());
format!("{}://{}{}", scheme, host, path)
}
fn get_host(&self) -> Option<String> {
self.headers
.get(hyper::header::HOST)
.and_then(|h| h.to_str().ok())
.map(|s| s.to_string())
}
}