2021-04-19 03:29:38 +01:00
|
|
|
//! Pre-defined `HeaderName`s, traits for parsing and conversion, and other header utility methods.
|
2019-02-07 13:24:24 -08:00
|
|
|
|
2023-01-02 13:33:31 +00:00
|
|
|
// declaring new header consts will yield this error
|
|
|
|
#![allow(clippy::declare_interior_mutable_const)]
|
|
|
|
|
2019-08-13 10:48:11 -07:00
|
|
|
use percent_encoding::{AsciiSet, CONTROLS};
|
2019-02-07 13:24:24 -08:00
|
|
|
|
2021-04-19 03:29:38 +01:00
|
|
|
// re-export from http except header map related items
|
2023-01-02 13:33:31 +00:00
|
|
|
pub use ::http::header::{
|
2021-04-19 03:29:38 +01:00
|
|
|
HeaderName, HeaderValue, InvalidHeaderName, InvalidHeaderValue, ToStrError,
|
|
|
|
};
|
|
|
|
|
2023-01-02 13:33:31 +00:00
|
|
|
// re-export const header names, list is explicit so that any updates to `common` module do not
|
|
|
|
// conflict with this set
|
|
|
|
pub use ::http::header::{
|
2021-04-19 03:29:38 +01:00
|
|
|
ACCEPT, ACCEPT_CHARSET, ACCEPT_ENCODING, ACCEPT_LANGUAGE, ACCEPT_RANGES,
|
|
|
|
ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS,
|
2021-12-08 06:01:11 +00:00
|
|
|
ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_EXPOSE_HEADERS,
|
|
|
|
ACCESS_CONTROL_MAX_AGE, ACCESS_CONTROL_REQUEST_HEADERS, ACCESS_CONTROL_REQUEST_METHOD, AGE,
|
|
|
|
ALLOW, ALT_SVC, AUTHORIZATION, CACHE_CONTROL, CONNECTION, CONTENT_DISPOSITION,
|
|
|
|
CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_LOCATION, CONTENT_RANGE,
|
|
|
|
CONTENT_SECURITY_POLICY, CONTENT_SECURITY_POLICY_REPORT_ONLY, CONTENT_TYPE, COOKIE, DATE,
|
|
|
|
DNT, ETAG, EXPECT, EXPIRES, FORWARDED, FROM, HOST, IF_MATCH, IF_MODIFIED_SINCE,
|
|
|
|
IF_NONE_MATCH, IF_RANGE, IF_UNMODIFIED_SINCE, LAST_MODIFIED, LINK, LOCATION, MAX_FORWARDS,
|
|
|
|
ORIGIN, PRAGMA, PROXY_AUTHENTICATE, PROXY_AUTHORIZATION, PUBLIC_KEY_PINS,
|
|
|
|
PUBLIC_KEY_PINS_REPORT_ONLY, RANGE, REFERER, REFERRER_POLICY, REFRESH, RETRY_AFTER,
|
|
|
|
SEC_WEBSOCKET_ACCEPT, SEC_WEBSOCKET_EXTENSIONS, SEC_WEBSOCKET_KEY, SEC_WEBSOCKET_PROTOCOL,
|
2021-04-19 03:29:38 +01:00
|
|
|
SEC_WEBSOCKET_VERSION, SERVER, SET_COOKIE, STRICT_TRANSPORT_SECURITY, TE, TRAILER,
|
2021-12-08 06:01:11 +00:00
|
|
|
TRANSFER_ENCODING, UPGRADE, UPGRADE_INSECURE_REQUESTS, USER_AGENT, VARY, VIA, WARNING,
|
|
|
|
WWW_AUTHENTICATE, X_CONTENT_TYPE_OPTIONS, X_DNS_PREFETCH_CONTROL, X_FRAME_OPTIONS,
|
|
|
|
X_XSS_PROTECTION,
|
2021-04-19 03:29:38 +01:00
|
|
|
};
|
2019-02-07 13:24:24 -08:00
|
|
|
|
2021-11-28 19:23:29 +00:00
|
|
|
use crate::{error::ParseError, HttpMessage};
|
2019-02-07 13:24:24 -08:00
|
|
|
|
2021-02-09 22:59:17 +00:00
|
|
|
mod as_name;
|
2023-01-02 13:33:31 +00:00
|
|
|
mod common;
|
2021-01-15 02:11:10 +00:00
|
|
|
mod into_pair;
|
|
|
|
mod into_value;
|
2021-11-29 02:22:47 +00:00
|
|
|
pub mod map;
|
2019-02-07 13:24:24 -08:00
|
|
|
mod shared;
|
2021-11-28 19:23:29 +00:00
|
|
|
mod utils;
|
2021-01-15 02:11:10 +00:00
|
|
|
|
2023-01-02 13:33:31 +00:00
|
|
|
pub use self::{
|
|
|
|
as_name::AsHeaderName,
|
|
|
|
into_pair::TryIntoHeaderPair,
|
|
|
|
into_value::TryIntoHeaderValue,
|
|
|
|
map::HeaderMap,
|
|
|
|
shared::{
|
|
|
|
parse_extended_value, q, Charset, ContentEncoding, ExtendedValue, HttpDate,
|
|
|
|
LanguageTag, Quality, QualityItem,
|
|
|
|
},
|
|
|
|
utils::{fmt_comma_delimited, from_comma_delimited, from_one_raw_str, http_percent_encode},
|
2021-12-05 03:38:08 +00:00
|
|
|
};
|
2023-01-02 13:33:31 +00:00
|
|
|
|
|
|
|
// re-export list is explicit so that any updates to `http` do not conflict with this set
|
|
|
|
pub use self::common::{
|
|
|
|
CROSS_ORIGIN_EMBEDDER_POLICY, CROSS_ORIGIN_OPENER_POLICY, CROSS_ORIGIN_RESOURCE_POLICY,
|
|
|
|
PERMISSIONS_POLICY, X_FORWARDED_FOR, X_FORWARDED_HOST, X_FORWARDED_PROTO,
|
2021-11-28 19:23:29 +00:00
|
|
|
};
|
2019-04-06 15:02:02 -07:00
|
|
|
|
2021-11-29 02:22:47 +00:00
|
|
|
/// An interface for types that already represent a valid header.
|
2021-12-13 16:08:08 +00:00
|
|
|
pub trait Header: TryIntoHeaderValue {
|
2022-01-03 18:46:04 +00:00
|
|
|
/// Returns the name of the header field.
|
2019-02-07 13:24:24 -08:00
|
|
|
fn name() -> HeaderName;
|
|
|
|
|
2022-01-03 18:46:04 +00:00
|
|
|
/// Parse the header from a HTTP message.
|
2021-12-02 13:59:25 +00:00
|
|
|
fn parse<M: HttpMessage>(msg: &M) -> Result<Self, ParseError>;
|
2019-02-07 13:24:24 -08:00
|
|
|
}
|
|
|
|
|
2021-01-15 05:38:50 +00:00
|
|
|
/// This encode set is used for HTTP header values and is defined at
|
2021-12-02 03:45:04 +00:00
|
|
|
/// <https://datatracker.ietf.org/doc/html/rfc5987#section-3.2>.
|
2019-08-13 10:48:11 -07:00
|
|
|
pub(crate) const HTTP_VALUE: &AsciiSet = &CONTROLS
|
|
|
|
.add(b' ')
|
|
|
|
.add(b'"')
|
|
|
|
.add(b'%')
|
|
|
|
.add(b'\'')
|
|
|
|
.add(b'(')
|
|
|
|
.add(b')')
|
|
|
|
.add(b'*')
|
|
|
|
.add(b',')
|
|
|
|
.add(b'/')
|
|
|
|
.add(b':')
|
|
|
|
.add(b';')
|
|
|
|
.add(b'<')
|
|
|
|
.add(b'-')
|
|
|
|
.add(b'>')
|
|
|
|
.add(b'?')
|
|
|
|
.add(b'[')
|
|
|
|
.add(b'\\')
|
|
|
|
.add(b']')
|
|
|
|
.add(b'{')
|
|
|
|
.add(b'}');
|