use http::HeaderMap;
use url::Url;
pub mod cache;
pub mod engine;
pub mod sources;
pub use cache::{CachedFingerprint, WarmCache};
pub use engine::Engine;
pub struct TargetContext<'a> {
pub final_url: &'a Url,
pub status: u16,
pub headers: &'a HeaderMap,
pub body: &'a [u8],
}
impl<'a> TargetContext<'a> {
pub fn http_only(
final_url: &'a Url,
status: u16,
headers: &'a HeaderMap,
body: &'a [u8],
) -> Self {
Self {
final_url,
status,
headers,
body,
}
}
pub fn host_label(&self) -> String {
let host = self.final_url.host_str().unwrap_or("");
let port = self
.final_url
.port()
.or_else(|| match self.final_url.scheme() {
"https" | "wss" => Some(443),
"http" | "ws" => Some(80),
_ => None,
})
.unwrap_or(0);
format!("{host}:{port}")
}
}