use super::header::Header;
pub static STATIC_TABLE: &[Header] = &[
Header::from_static(b":authority", b""),
Header::from_static(b":path", b"/"),
Header::from_static(b"age", b"0"),
Header::from_static(b"content-disposition", b""),
Header::from_static(b"content-length", b"0"),
Header::from_static(b"cookie", b""),
Header::from_static(b"date", b""),
Header::from_static(b"etag", b""),
Header::from_static(b"if-modified-since", b""),
Header::from_static(b"if-none-match", b""),
Header::from_static(b"last-modified", b""),
Header::from_static(b"link", b""),
Header::from_static(b"location", b""),
Header::from_static(b"referer", b""),
Header::from_static(b"set-cookie", b""),
Header::from_static(b":method", b"CONNECT"),
Header::from_static(b":method", b"DELETE"),
Header::from_static(b":method", b"GET"),
Header::from_static(b":method", b"HEAD"),
Header::from_static(b":method", b"OPTIONS"),
Header::from_static(b":method", b"POST"),
Header::from_static(b":method", b"PUT"),
Header::from_static(b":scheme", b"http"),
Header::from_static(b":scheme", b"https"),
Header::from_static(b":status", b"103"),
Header::from_static(b":status", b"200"),
Header::from_static(b":status", b"304"),
Header::from_static(b":status", b"404"),
Header::from_static(b":status", b"503"),
Header::from_static(b"accept", b"*/*"),
Header::from_static(b"accept", b"application/dns-message"),
Header::from_static(b"accept-encoding", b"gzip, deflate, br"),
Header::from_static(b"accept-ranges", b"bytes"),
Header::from_static(b"access-control-allow-headers", b"cache-control"),
Header::from_static(b"access-control-allow-headers", b"content-type"),
Header::from_static(b"access-control-allow-origin", b"*"),
Header::from_static(b"cache-control", b"max-age=0"),
Header::from_static(b"cache-control", b"max-age=2592000"),
Header::from_static(b"cache-control", b"max-age=604800"),
Header::from_static(b"cache-control", b"no-cache"),
Header::from_static(b"cache-control", b"no-store"),
Header::from_static(b"cache-control", b"public, max-age=31536000"),
Header::from_static(b"content-encoding", b"br"),
Header::from_static(b"content-encoding", b"gzip"),
Header::from_static(b"content-type", b"application/dns-message"),
Header::from_static(b"content-type", b"application/javascript"),
Header::from_static(b"content-type", b"application/json"),
Header::from_static(b"content-type", b"application/x-www-form-urlencoded"),
Header::from_static(b"content-type", b"image/gif"),
Header::from_static(b"content-type", b"image/jpeg"),
Header::from_static(b"content-type", b"image/png"),
Header::from_static(b"content-type", b"text/css"),
Header::from_static(b"content-type", b"text/html; charset=utf-8"),
Header::from_static(b"content-type", b"text/plain"),
Header::from_static(b"content-type", b"text/plain;charset=utf-8"),
Header::from_static(b"range", b"bytes=0-"),
Header::from_static(b"strict-transport-security", b"max-age=31536000"),
Header::from_static(
b"strict-transport-security",
b"max-age=31536000; includesubdomains",
),
Header::from_static(
b"strict-transport-security",
b"max-age=31536000; includesubdomains; preload",
),
Header::from_static(b"vary", b"accept-encoding"),
Header::from_static(b"vary", b"origin"),
Header::from_static(b"x-content-type-options", b"nosniff"),
Header::from_static(b"x-xss-protection", b"1; mode=block"),
Header::from_static(b":status", b"100"),
Header::from_static(b":status", b"204"),
Header::from_static(b":status", b"206"),
Header::from_static(b":status", b"302"),
Header::from_static(b":status", b"400"),
Header::from_static(b":status", b"403"),
Header::from_static(b":status", b"421"),
Header::from_static(b":status", b"425"),
Header::from_static(b":status", b"500"),
Header::from_static(b"accept-language", b""),
Header::from_static(b"access-control-allow-credentials", b"FALSE"),
Header::from_static(b"access-control-allow-credentials", b"TRUE"),
Header::from_static(b"access-control-allow-headers", b"*"),
Header::from_static(b"access-control-allow-methods", b"get"),
Header::from_static(b"access-control-allow-methods", b"get, post, options"),
Header::from_static(b"access-control-allow-methods", b"options"),
Header::from_static(b"access-control-expose-headers", b"content-length"),
Header::from_static(b"access-control-request-headers", b"content-type"),
Header::from_static(b"access-control-request-method", b"get"),
Header::from_static(b"access-control-request-method", b"post"),
Header::from_static(b"alt-svc", b"clear"),
Header::from_static(b"authorization", b""),
Header::from_static(
b"content-security-policy",
b"script-src 'none'; object-src 'none'; base-uri 'none'",
),
Header::from_static(b"early-data", b"1"),
Header::from_static(b"expect-ct", b""),
Header::from_static(b"forwarded", b""),
Header::from_static(b"if-range", b""),
Header::from_static(b"origin", b""),
Header::from_static(b"purpose", b"prefetch"),
Header::from_static(b"server", b""),
Header::from_static(b"timing-allow-origin", b"*"),
Header::from_static(b"upgrade-insecure-requests", b"1"),
Header::from_static(b"user-agent", b""),
Header::from_static(b"x-forwarded-for", b""),
Header::from_static(b"x-frame-options", b"deny"),
Header::from_static(b"x-frame-options", b"sameorigin"),
];
pub const STATIC_TABLE_LEN: usize = 99;
#[inline]
pub fn get_static_entry(index: usize) -> Option<&'static Header> {
STATIC_TABLE.get(index)
}
pub fn find_static_entry(name: &[u8], value: &[u8]) -> (Option<usize>, Option<usize>) {
let mut name_match = None;
for (index, entry) in STATIC_TABLE.iter().enumerate() {
if entry.name() == name {
if entry.value() == value {
return (Some(index), Some(index));
}
if name_match.is_none() {
name_match = Some(index);
}
}
}
(None, name_match)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_static_table_len() {
assert_eq!(STATIC_TABLE.len(), STATIC_TABLE_LEN);
assert_eq!(STATIC_TABLE_LEN, 99);
}
#[test]
fn test_get_static_entry() {
let entry = get_static_entry(0).unwrap();
assert_eq!(entry.name(), b":authority");
assert_eq!(entry.value(), b"");
let entry = get_static_entry(17).unwrap();
assert_eq!(entry.name(), b":method");
assert_eq!(entry.value(), b"GET");
let entry = get_static_entry(25).unwrap();
assert_eq!(entry.name(), b":status");
assert_eq!(entry.value(), b"200");
let entry = get_static_entry(98).unwrap();
assert_eq!(entry.name(), b"x-frame-options");
assert_eq!(entry.value(), b"sameorigin");
assert!(get_static_entry(99).is_none());
}
#[test]
fn test_find_static_entry_exact_match() {
let (exact, name_only) = find_static_entry(b":method", b"GET");
assert_eq!(exact, Some(17));
assert_eq!(name_only, Some(17));
let (exact, name_only) = find_static_entry(b":status", b"200");
assert_eq!(exact, Some(25));
assert_eq!(name_only, Some(25));
}
#[test]
fn test_find_static_entry_name_only() {
let (exact, name_only) = find_static_entry(b":method", b"PATCH");
assert_eq!(exact, None);
assert_eq!(name_only, Some(15));
let (exact, name_only) = find_static_entry(b":status", b"201");
assert_eq!(exact, None);
assert_eq!(name_only, Some(24)); }
#[test]
fn test_find_static_entry_not_found() {
let (exact, name_only) = find_static_entry(b"x-custom-header", b"value");
assert_eq!(exact, None);
assert_eq!(name_only, None);
}
}