use crate::{
cache_control::CacheControl,
common::file::{File as File_, FileArchived},
};
use http::HeaderValue;
pub trait File {
fn content(&self) -> &[u8];
fn content_gzip(&self) -> Option<&[u8]>;
fn content_brotli(&self) -> Option<&[u8]>;
fn content_type(&self) -> HeaderValue;
fn etag(&self) -> HeaderValue;
fn cache_control(&self) -> CacheControl;
}
impl File for File_ {
fn content(&self) -> &[u8] {
&self.content
}
fn content_gzip(&self) -> Option<&[u8]> {
self.content_gzip.as_deref()
}
fn content_brotli(&self) -> Option<&[u8]> {
self.content_brotli.as_deref()
}
fn content_type(&self) -> HeaderValue {
HeaderValue::from_str(&self.content_type).unwrap()
}
fn etag(&self) -> HeaderValue {
HeaderValue::from_str(&self.etag).unwrap()
}
fn cache_control(&self) -> CacheControl {
CacheControl::from(self.cache_control)
}
}
impl File for FileArchived {
fn content(&self) -> &[u8] {
&self.content
}
fn content_gzip(&self) -> Option<&[u8]> {
self.content_gzip.as_deref()
}
fn content_brotli(&self) -> Option<&[u8]> {
self.content_brotli.as_deref()
}
fn content_type(&self) -> HeaderValue {
HeaderValue::from_str(&self.content_type).unwrap()
}
fn etag(&self) -> HeaderValue {
HeaderValue::from_str(&self.etag).unwrap()
}
fn cache_control(&self) -> CacheControl {
CacheControl::from(self.cache_control)
}
}