use hitbox::{CacheStatus, CacheStatusExt};
use http::{HeaderValue, header::HeaderName};
use hyper::body::Body as HttpBody;
use crate::CacheableHttpResponse;
pub const DEFAULT_CACHE_STATUS_HEADER: HeaderName = HeaderName::from_static("x-cache-status");
impl<ResBody> CacheStatusExt for CacheableHttpResponse<ResBody>
where
ResBody: HttpBody,
{
type Config = HeaderName;
fn cache_status(&mut self, status: CacheStatus, config: &Self::Config) {
let value = match status {
CacheStatus::Hit => HeaderValue::from_static("HIT"),
CacheStatus::Miss => HeaderValue::from_static("MISS"),
CacheStatus::Stale => HeaderValue::from_static("STALE"),
};
self.parts.headers.insert(config.clone(), value);
}
}