hitbox_http/
cache_status.rs1use hitbox::{CacheStatus, CacheStatusExt};
7use http::{HeaderValue, header::HeaderName};
8use hyper::body::Body as HttpBody;
9
10use crate::CacheableHttpResponse;
11
12pub const DEFAULT_CACHE_STATUS_HEADER: HeaderName = HeaderName::from_static("x-cache-status");
17
18impl<ResBody> CacheStatusExt for CacheableHttpResponse<ResBody>
19where
20 ResBody: HttpBody,
21{
22 type Config = HeaderName;
23
24 fn cache_status(&mut self, status: CacheStatus, config: &Self::Config) {
25 let value = match status {
26 CacheStatus::Hit => HeaderValue::from_static("HIT"),
27 CacheStatus::Miss => HeaderValue::from_static("MISS"),
28 CacheStatus::Stale => HeaderValue::from_static("STALE"),
29 };
30 self.parts.headers.insert(config.clone(), value);
31 }
32}