http/header/
mod.rs

1//! HTTP header types
2//!
3//! The module provides [`HeaderName`], [`HeaderMap`], and a number of types
4//! used for interacting with `HeaderMap`. These types allow representing both
5//! HTTP/1 and HTTP/2 headers.
6//!
7//! # `HeaderName`
8//!
9//! The `HeaderName` type represents both standard header names as well as
10//! custom header names. The type handles the case insensitive nature of header
11//! names and is used as the key portion of `HeaderMap`. Header names are
12//! normalized to lower case. In other words, when creating a `HeaderName` with
13//! a string, even if upper case characters are included, when getting a string
14//! representation of the `HeaderName`, it will be all lower case. This allows
15//! for faster `HeaderMap` comparison operations.
16//!
17//! The internal representation is optimized to efficiently handle the cases
18//! most commonly encountered when working with HTTP. Standard header names are
19//! special cased and are represented internally as an enum. Short custom
20//! headers will be stored directly in the `HeaderName` struct and will not
21//! incur any allocation overhead, however longer strings will require an
22//! allocation for storage.
23//!
24//! ## Limitations
25//!
26//! `HeaderName` has a max length of 32,768 for header names. Attempting to
27//! parse longer names will result in a panic.
28//!
29//! # `HeaderMap`
30//!
31//! The [`HeaderMap`] type is a specialized
32//! [multimap](<https://en.wikipedia.org/wiki/Multimap>) structure for storing
33//! header names and values. It is designed specifically for efficient
34//! manipulation of HTTP headers. It supports multiple values per header name
35//! and provides specialized APIs for insertion, retrieval, and iteration.
36//!
37//! [*See also the `HeaderMap` type.*](HeaderMap)
38
39mod map;
40mod name;
41mod value;
42
43pub use self::map::{
44    AsHeaderName, Drain, Entry, GetAll, HeaderMap, IntoHeaderName, IntoIter, Iter, IterMut, Keys,
45    MaxSizeReached, OccupiedEntry, VacantEntry, ValueDrain, ValueIter, ValueIterMut, Values,
46    ValuesMut,
47};
48pub use self::name::{HeaderName, InvalidHeaderName};
49pub use self::value::{HeaderValue, InvalidHeaderValue, ToStrError};
50
51// Use header name constants
52#[rustfmt::skip]
53pub use self::name::{
54    ACCEPT,
55    ACCEPT_CHARSET,
56    ACCEPT_ENCODING,
57    ACCEPT_LANGUAGE,
58    ACCEPT_RANGES,
59    ACCESS_CONTROL_ALLOW_CREDENTIALS,
60    ACCESS_CONTROL_ALLOW_HEADERS,
61    ACCESS_CONTROL_ALLOW_METHODS,
62    ACCESS_CONTROL_ALLOW_ORIGIN,
63    ACCESS_CONTROL_EXPOSE_HEADERS,
64    ACCESS_CONTROL_MAX_AGE,
65    ACCESS_CONTROL_REQUEST_HEADERS,
66    ACCESS_CONTROL_REQUEST_METHOD,
67    AGE,
68    ALLOW,
69    ALT_SVC,
70    AUTHORIZATION,
71    CACHE_CONTROL,
72    CACHE_STATUS,
73    CDN_CACHE_CONTROL,
74    CONNECTION,
75    CONTENT_DISPOSITION,
76    CONTENT_ENCODING,
77    CONTENT_LANGUAGE,
78    CONTENT_LENGTH,
79    CONTENT_LOCATION,
80    CONTENT_RANGE,
81    CONTENT_SECURITY_POLICY,
82    CONTENT_SECURITY_POLICY_REPORT_ONLY,
83    CONTENT_TYPE,
84    COOKIE,
85    DNT,
86    DATE,
87    ETAG,
88    EXPECT,
89    EXPIRES,
90    FORWARDED,
91    FROM,
92    HOST,
93    IF_MATCH,
94    IF_MODIFIED_SINCE,
95    IF_NONE_MATCH,
96    IF_RANGE,
97    IF_UNMODIFIED_SINCE,
98    LAST_MODIFIED,
99    LINK,
100    LOCATION,
101    MAX_FORWARDS,
102    ORIGIN,
103    PRAGMA,
104    PROXY_AUTHENTICATE,
105    PROXY_AUTHORIZATION,
106    PUBLIC_KEY_PINS,
107    PUBLIC_KEY_PINS_REPORT_ONLY,
108    RANGE,
109    REFERER,
110    REFERRER_POLICY,
111    REFRESH,
112    RETRY_AFTER,
113    SEC_WEBSOCKET_ACCEPT,
114    SEC_WEBSOCKET_EXTENSIONS,
115    SEC_WEBSOCKET_KEY,
116    SEC_WEBSOCKET_PROTOCOL,
117    SEC_WEBSOCKET_VERSION,
118    SERVER,
119    SET_COOKIE,
120    STRICT_TRANSPORT_SECURITY,
121    TE,
122    TRAILER,
123    TRANSFER_ENCODING,
124    UPGRADE,
125    UPGRADE_INSECURE_REQUESTS,
126    USER_AGENT,
127    VARY,
128    VIA,
129    WARNING,
130    WWW_AUTHENTICATE,
131    X_CONTENT_TYPE_OPTIONS,
132    X_DNS_PREFETCH_CONTROL,
133    X_FRAME_OPTIONS,
134    X_XSS_PROTECTION,
135};
136
137/// Maximum length of a header name
138///
139/// Generally, 64kb for a header name is WAY too much than would ever be needed
140/// in practice. Restricting it to this size enables using `u16` values to
141/// represent offsets when dealing with header names.
142const MAX_HEADER_NAME_LEN: usize = (1 << 16) - 1;