Skip to main content

rama_http_headers/common/
mod.rs

1//! A Collection of Header implementations for common HTTP Headers.
2//!
3//! ## Mime
4//!
5//! Several header fields use MIME values for their contents. Keeping with the
6//! strongly-typed theme, the [mime](https://docs.rs/mime) crate
7//! is used, such as `ContentType(pub Mime)`.
8
9//pub use self::accept_charset::AcceptCharset;
10// pub use self::accept_encoding::AcceptEncoding;
11//pub use self::accept_language::AcceptLanguage;
12pub use self::accept::Accept;
13pub use self::accept_ranges::AcceptRanges;
14pub use self::access_control_allow_credentials::AccessControlAllowCredentials;
15pub use self::access_control_allow_headers::AccessControlAllowHeaders;
16pub use self::access_control_allow_methods::AccessControlAllowMethods;
17pub use self::access_control_allow_origin::AccessControlAllowOrigin;
18pub use self::access_control_allow_private_network::AccessControlAllowPrivateNetwork;
19pub use self::access_control_expose_headers::AccessControlExposeHeaders;
20pub use self::access_control_max_age::AccessControlMaxAge;
21pub use self::access_control_request_headers::AccessControlRequestHeaders;
22pub use self::access_control_request_method::AccessControlRequestMethod;
23pub use self::access_control_request_private_network::AccessControlRequestPrivateNetwork;
24pub use self::age::Age;
25pub use self::allow::Allow;
26pub use self::authorization::Authorization;
27pub use self::cache_control::CacheControl;
28pub use self::connection::Connection;
29pub use self::content_disposition::ContentDisposition;
30pub use self::content_encoding::{ContentEncoding, ContentEncodingDirective};
31//pub use self::content_language::ContentLanguage;
32pub use self::content_length::ContentLength;
33pub use self::content_location::ContentLocation;
34pub use self::content_range::ContentRange;
35pub use self::content_security_policy::{
36    ContentSecurityPolicy, Directive, DirectiveName, HashAlgorithm, HostSource, HostSourcePort,
37    SourceExpression, SourceList,
38};
39pub use self::content_type::ContentType;
40pub use self::cookie::Cookie;
41pub use self::cross_origin_embedder_policy::{
42    CrossOriginEmbedderPolicy, CrossOriginEmbedderPolicyReportOnly, CrossOriginEmbedderPolicyValue,
43};
44pub use self::cross_origin_opener_policy::{
45    CrossOriginOpenerPolicy, CrossOriginOpenerPolicyReportOnly, CrossOriginOpenerPolicyValue,
46};
47pub use self::cross_origin_resource_policy::CrossOriginResourcePolicy;
48pub use self::date::Date;
49pub use self::etag::ETag;
50pub use self::expect::Expect;
51pub use self::expires::Expires;
52//pub use self::from::From;
53pub use self::host::Host;
54pub use self::if_match::IfMatch;
55pub use self::if_modified_since::IfModifiedSince;
56pub use self::if_none_match::IfNoneMatch;
57pub use self::if_range::IfRange;
58pub use self::if_unmodified_since::IfUnmodifiedSince;
59pub use self::last_event_id::LastEventId;
60pub use self::last_modified::LastModified;
61//pub use self::link::{Link, LinkValue, RelationType, MediaDesc};
62pub use self::location::Location;
63pub use self::origin::Origin;
64pub use self::permissions_policy::{
65    AllowlistSource, PermissionsPolicy, PermissionsPolicyDirective, PermissionsPolicyDirectiveName,
66};
67pub use self::pragma::Pragma;
68//pub use self::prefer::{Prefer, Preference};
69//pub use self::preference_applied::PreferenceApplied;
70pub use self::proxy_authorization::ProxyAuthorization;
71pub use self::range::{ByteRangeSpec, Range};
72pub use self::referer::Referer;
73pub use self::referrer_policy::ReferrerPolicy;
74pub use self::retry_after::{After, RetryAfter};
75pub use self::sec_fetch_site::SecFetchSite;
76pub use self::sec_websocket_accept::SecWebSocketAccept;
77pub use self::sec_websocket_extensions::SecWebSocketExtensions;
78pub use self::sec_websocket_key::SecWebSocketKey;
79pub use self::sec_websocket_protocol::SecWebSocketProtocol;
80pub use self::sec_websocket_version::SecWebSocketVersion;
81pub use self::server::Server;
82pub use self::set_cookie::SetCookie;
83pub use self::strict_transport_security::StrictTransportSecurity;
84pub use self::te::{Te, TeDirective};
85pub use self::transfer_encoding::{TransferEncoding, TransferEncodingDirective};
86pub use self::upgrade::Upgrade;
87pub use self::user_agent::UserAgent;
88pub use self::vary::Vary;
89//pub use self::warning::Warning;
90pub use self::x_content_type_options::XContentTypeOptions;
91pub use self::x_frame_options::XFrameOptions;
92
93#[cfg(test)]
94fn test_decode<T: crate::HeaderDecode>(values: &[&str]) -> Option<T> {
95    use crate::HeaderMapExt;
96    let mut map = ::rama_http_types::HeaderMap::new();
97    for val in values {
98        map.append(T::name(), val.parse().unwrap());
99    }
100    map.typed_get()
101}
102
103#[cfg(test)]
104fn test_encode<T: crate::HeaderEncode>(header: T) -> ::rama_http_types::HeaderMap {
105    use crate::HeaderMapExt;
106    let mut map = ::rama_http_types::HeaderMap::new();
107    map.typed_insert(header);
108    map
109}
110
111#[cfg(test)]
112macro_rules! bench_header {
113    ($mod:ident, $ty:ident, $value:expr) => {
114        #[cfg(nightly)]
115        mod $mod {
116            use super::$ty;
117            use crate::HeaderMapExt;
118
119            #[bench]
120            fn bench_decode(b: &mut ::test::Bencher) {
121                let mut map = ::rama_http_types::HeaderMap::new();
122                map.append(
123                    <$ty as crate::Header>::name(),
124                    $value.parse().expect("HeaderValue::from_str($value)"),
125                );
126                b.bytes = $value.len() as u64;
127                b.iter(|| {
128                    map.typed_get::<$ty>().unwrap();
129                });
130            }
131
132            #[bench]
133            fn bench_encode(b: &mut ::test::Bencher) {
134                let mut map = ::rama_http_types::HeaderMap::new();
135                map.append(
136                    <$ty as crate::Header>::name(),
137                    $value.parse().expect("HeaderValue::from_str($value)"),
138                );
139                let typed = map.typed_get::<$ty>().unwrap();
140                b.bytes = $value.len() as u64;
141                b.iter(|| {
142                    map.typed_insert(typed.clone());
143                    map.clear();
144                });
145            }
146        }
147    };
148}
149
150mod accept;
151//mod accept_charset;
152// mod accept_encoding;
153//mod accept_language;
154mod accept_ranges;
155mod access_control_allow_credentials;
156mod access_control_allow_headers;
157mod access_control_allow_methods;
158mod access_control_allow_origin;
159mod access_control_allow_private_network;
160mod access_control_expose_headers;
161mod access_control_max_age;
162mod access_control_request_headers;
163mod access_control_request_method;
164mod access_control_request_private_network;
165mod age;
166mod allow;
167pub mod authorization;
168mod cache_control;
169mod connection;
170mod content_disposition;
171mod content_encoding;
172//mod content_language;
173mod content_length;
174mod content_location;
175mod content_range;
176mod content_security_policy;
177mod content_type;
178mod cookie;
179mod cross_origin_embedder_policy;
180mod cross_origin_opener_policy;
181mod cross_origin_policy_util;
182mod cross_origin_resource_policy;
183mod date;
184mod etag;
185mod expect;
186mod expires;
187//mod from;
188mod host;
189mod if_match;
190mod if_modified_since;
191mod if_none_match;
192mod if_range;
193mod if_unmodified_since;
194mod last_event_id;
195mod last_modified;
196//mod link;
197mod location;
198mod origin;
199mod permissions_policy;
200mod pragma;
201//mod prefer;
202//mod preference_applied;
203mod proxy_authorization;
204mod range;
205mod referer;
206mod referrer_policy;
207mod retry_after;
208mod sec_fetch_site;
209mod sec_websocket_accept;
210pub mod sec_websocket_extensions;
211mod sec_websocket_key;
212pub mod sec_websocket_protocol;
213mod sec_websocket_version;
214mod server;
215mod set_cookie;
216mod strict_transport_security;
217mod te;
218mod transfer_encoding;
219mod upgrade;
220mod user_agent;
221mod vary;
222//mod warning;
223mod x_content_type_options;
224mod x_frame_options;