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_ranges::AcceptRanges;
13//pub use self::accept::Accept;
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_expose_headers::AccessControlExposeHeaders;
19pub use self::access_control_max_age::AccessControlMaxAge;
20pub use self::access_control_request_headers::AccessControlRequestHeaders;
21pub use self::access_control_request_method::AccessControlRequestMethod;
22pub use self::age::Age;
23pub use self::allow::Allow;
24pub use self::authorization::Authorization;
25pub use self::cache_control::CacheControl;
26pub use self::connection::Connection;
27pub use self::content_disposition::ContentDisposition;
28pub use self::content_encoding::ContentEncoding;
29//pub use self::content_language::ContentLanguage;
30pub use self::content_length::ContentLength;
31pub use self::content_location::ContentLocation;
32pub use self::content_range::ContentRange;
33pub use self::content_type::ContentType;
34pub use self::cookie::Cookie;
35pub use self::date::Date;
36pub use self::etag::ETag;
37pub use self::expect::Expect;
38pub use self::expires::Expires;
39//pub use self::from::From;
40pub use self::host::Host;
41pub use self::if_match::IfMatch;
42pub use self::if_modified_since::IfModifiedSince;
43pub use self::if_none_match::IfNoneMatch;
44pub use self::if_range::IfRange;
45pub use self::if_unmodified_since::IfUnmodifiedSince;
46//pub use self::last_event_id::LastEventId;
47pub use self::last_modified::LastModified;
48//pub use self::link::{Link, LinkValue, RelationType, MediaDesc};
49pub use self::location::Location;
50pub use self::origin::Origin;
51pub use self::pragma::Pragma;
52//pub use self::prefer::{Prefer, Preference};
53//pub use self::preference_applied::PreferenceApplied;
54pub use self::proxy_authorization::ProxyAuthorization;
55pub use self::range::Range;
56pub use self::referer::Referer;
57pub use self::referrer_policy::ReferrerPolicy;
58pub use self::retry_after::RetryAfter;
59pub use self::sec_websocket_accept::SecWebsocketAccept;
60pub use self::sec_websocket_key::SecWebsocketKey;
61pub use self::sec_websocket_version::SecWebsocketVersion;
62pub use self::server::Server;
63pub use self::set_cookie::SetCookie;
64pub use self::strict_transport_security::StrictTransportSecurity;
65pub use self::te::Te;
66pub use self::transfer_encoding::TransferEncoding;
67pub use self::upgrade::Upgrade;
68pub use self::user_agent::UserAgent;
69pub use self::vary::Vary;
70//pub use self::warning::Warning;
71
72#[cfg(test)]
73fn test_decode<T: ::Header>(values: &[&str]) -> Option<T> {
74    use HeaderMapExt;
75    let mut map = ::http::HeaderMap::new();
76    for val in values {
77        map.append(T::name(), val.parse().unwrap());
78    }
79    map.typed_get()
80}
81
82#[cfg(test)]
83fn test_encode<T: ::Header>(header: T) -> ::http::HeaderMap {
84    use HeaderMapExt;
85    let mut map = ::http::HeaderMap::new();
86    map.typed_insert(header);
87    map
88}
89
90#[cfg(test)]
91macro_rules! bench_header {
92    ($mod:ident, $ty:ident, $value:expr) => {
93        #[cfg(feature = "nightly")]
94        mod $mod {
95            use super::$ty;
96            use HeaderMapExt;
97
98            #[bench]
99            fn bench_decode(b: &mut ::test::Bencher) {
100                let mut map = ::http::HeaderMap::new();
101                map.append(
102                    <$ty as ::Header>::name(),
103                    $value.parse().expect("HeaderValue::from_str($value)"),
104                );
105                b.bytes = $value.len() as u64;
106                b.iter(|| {
107                    map.typed_get::<$ty>().unwrap();
108                });
109            }
110
111            #[bench]
112            fn bench_encode(b: &mut ::test::Bencher) {
113                let mut map = ::http::HeaderMap::new();
114                map.append(
115                    <$ty as ::Header>::name(),
116                    $value.parse().expect("HeaderValue::from_str($value)"),
117                );
118                let typed = map.typed_get::<$ty>().unwrap();
119                b.bytes = $value.len() as u64;
120                b.iter(|| {
121                    map.typed_insert(typed.clone());
122                    map.clear();
123                });
124            }
125        }
126    };
127}
128
129//mod accept;
130//mod accept_charset;
131//mod accept_encoding;
132//mod accept_language;
133mod accept_ranges;
134mod access_control_allow_credentials;
135mod access_control_allow_headers;
136mod access_control_allow_methods;
137mod access_control_allow_origin;
138mod access_control_expose_headers;
139mod access_control_max_age;
140mod access_control_request_headers;
141mod access_control_request_method;
142mod age;
143mod allow;
144pub mod authorization;
145mod cache_control;
146mod connection;
147mod content_disposition;
148mod content_encoding;
149//mod content_language;
150mod content_length;
151mod content_location;
152mod content_range;
153mod content_type;
154mod cookie;
155mod date;
156mod etag;
157mod expect;
158mod expires;
159//mod from;
160mod host;
161mod if_match;
162mod if_modified_since;
163mod if_none_match;
164mod if_range;
165mod if_unmodified_since;
166//mod last_event_id;
167mod last_modified;
168//mod link;
169mod location;
170mod origin;
171mod pragma;
172//mod prefer;
173//mod preference_applied;
174mod proxy_authorization;
175mod range;
176mod referer;
177mod referrer_policy;
178mod retry_after;
179mod sec_websocket_accept;
180mod sec_websocket_key;
181mod sec_websocket_version;
182mod server;
183mod set_cookie;
184mod strict_transport_security;
185mod te;
186mod transfer_encoding;
187mod upgrade;
188mod user_agent;
189mod vary;
190//mod warning;