1use crate::{
4 cache_control::CacheControl,
5 common::file::{File as File_, FileArchived},
6};
7use http::HeaderValue;
8
9pub trait File {
19 fn content(&self) -> &[u8];
22 fn content_gzip(&self) -> Option<&[u8]>;
24 fn content_brotli(&self) -> Option<&[u8]>;
26
27 fn content_type(&self) -> HeaderValue;
30 fn etag(&self) -> HeaderValue;
32 fn cache_control(&self) -> CacheControl;
34}
35impl File for File_ {
36 fn content(&self) -> &[u8] {
37 &self.content
38 }
39 fn content_gzip(&self) -> Option<&[u8]> {
40 self.content_gzip.as_deref()
41 }
42 fn content_brotli(&self) -> Option<&[u8]> {
43 self.content_brotli.as_deref()
44 }
45
46 fn content_type(&self) -> HeaderValue {
47 HeaderValue::from_str(&self.content_type).unwrap()
48 }
49 fn etag(&self) -> HeaderValue {
50 HeaderValue::from_str(&self.etag).unwrap()
51 }
52 fn cache_control(&self) -> CacheControl {
53 CacheControl::from(self.cache_control)
54 }
55}
56impl File for FileArchived {
57 fn content(&self) -> &[u8] {
58 &self.content
59 }
60 fn content_gzip(&self) -> Option<&[u8]> {
61 self.content_gzip.as_deref()
62 }
63 fn content_brotli(&self) -> Option<&[u8]> {
64 self.content_brotli.as_deref()
65 }
66
67 fn content_type(&self) -> HeaderValue {
68 HeaderValue::from_str(&self.content_type).unwrap()
69 }
70 fn etag(&self) -> HeaderValue {
71 HeaderValue::from_str(&self.etag).unwrap()
72 }
73 fn cache_control(&self) -> CacheControl {
74 CacheControl::from(self.cache_control)
75 }
76}