kutil_http/headers/
custom.rs

1use super::headers::*;
2
3use {http::*, std::time::*};
4
5/// `XX-Cache` HTTP response header specifying whether to cache the response.
6pub const XX_CACHE: HeaderName = HeaderName::from_static("xx-cache");
7
8/// `XX-Cache-Duration` HTTP response header specifying the cache duration in seconds.
9pub const XX_CACHE_DURATION: HeaderName = HeaderName::from_static("xx-cache-duration");
10
11/// `XX-Encode` HTTP response header specifying whether to encode the response.
12pub const XX_ENCODE: HeaderName = HeaderName::from_static("xx-encode");
13
14/// `Content-Digest` HTTP response header.
15///
16/// See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Digest).
17///
18/// Non-standard but ... just in case.
19pub const CONTENT_DIGEST: HeaderName = HeaderName::from_static("content-digest");
20
21//
22// CustomHeaderValues
23//
24
25/// Access custom header values.
26pub trait CustomHeaderValues {
27    /// Parse `XX-Cache` response header value.
28    fn xx_cache(&self, default: bool) -> bool;
29
30    /// Parse `XX-Cache-Duration` response header value.
31    fn xx_cache_duration(&self) -> Option<Duration>;
32
33    /// Parse `XX-Encode` response header value.
34    fn xx_encode(&self, default: bool) -> bool;
35}
36
37impl CustomHeaderValues for HeaderMap {
38    fn xx_cache(&self, default: bool) -> bool {
39        self.bool_value(XX_CACHE, default)
40    }
41
42    fn xx_cache_duration(&self) -> Option<Duration> {
43        self.duration_value(XX_CACHE_DURATION)
44    }
45
46    fn xx_encode(&self, default: bool) -> bool {
47        self.bool_value(XX_ENCODE, default)
48    }
49}