perf(headers): check for header literals before allocating name
This commit is contained in:
@@ -42,7 +42,8 @@ const ACCESS_CONTROL_ALLOW_CREDENTIALS_TRUE: UniCase<&'static str> = UniCase("tr
|
||||
|
||||
impl Header for AccessControlAllowCredentials {
|
||||
fn header_name() -> &'static str {
|
||||
"Access-Control-Allow-Credentials"
|
||||
static NAME: &'static str = "Access-Control-Allow-Credentials";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<AccessControlAllowCredentials> {
|
||||
|
||||
@@ -73,7 +73,8 @@ impl<S: Scheme> DerefMut for Authorization<S> {
|
||||
|
||||
impl<S: Scheme + Any> Header for Authorization<S> where <S as FromStr>::Err: 'static {
|
||||
fn header_name() -> &'static str {
|
||||
"Authorization"
|
||||
static NAME: &'static str = "Authorization";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Authorization<S>> {
|
||||
|
||||
@@ -51,7 +51,8 @@ __hyper__deref!(CacheControl => Vec<CacheDirective>);
|
||||
|
||||
impl Header for CacheControl {
|
||||
fn header_name() -> &'static str {
|
||||
"Cache-Control"
|
||||
static NAME: &'static str = "Cache-Control";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<CacheControl> {
|
||||
|
||||
@@ -90,7 +90,8 @@ pub struct ContentDisposition {
|
||||
|
||||
impl Header for ContentDisposition {
|
||||
fn header_name() -> &'static str {
|
||||
"Content-Disposition"
|
||||
static NAME: &'static str = "Content-Disposition";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<ContentDisposition> {
|
||||
|
||||
@@ -32,10 +32,13 @@ use header::{Header, parsing};
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct ContentLength(pub u64);
|
||||
|
||||
//static NAME: &'static str = "Content-Length";
|
||||
|
||||
impl Header for ContentLength {
|
||||
#[inline]
|
||||
fn header_name() -> &'static str {
|
||||
"Content-Length"
|
||||
static NAME: &'static str = "Content-Length";
|
||||
NAME
|
||||
}
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<ContentLength> {
|
||||
// If multiple Content-Length headers were sent, everything can still
|
||||
|
||||
@@ -39,7 +39,8 @@ __hyper__deref!(Cookie => Vec<CookiePair>);
|
||||
|
||||
impl Header for Cookie {
|
||||
fn header_name() -> &'static str {
|
||||
"Cookie"
|
||||
static NAME: &'static str = "Cookie";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Cookie> {
|
||||
|
||||
@@ -30,7 +30,8 @@ const EXPECT_CONTINUE: UniCase<&'static str> = UniCase("100-continue");
|
||||
|
||||
impl Header for Expect {
|
||||
fn header_name() -> &'static str {
|
||||
"Expect"
|
||||
static NAME: &'static str = "Expect";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Expect> {
|
||||
|
||||
@@ -43,7 +43,8 @@ pub struct Host {
|
||||
|
||||
impl Header for Host {
|
||||
fn header_name() -> &'static str {
|
||||
"Host"
|
||||
static NAME: &'static str = "Host";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Host> {
|
||||
|
||||
@@ -55,7 +55,8 @@ pub enum IfRange {
|
||||
|
||||
impl Header for IfRange {
|
||||
fn header_name() -> &'static str {
|
||||
"If-Range"
|
||||
static NAME: &'static str = "If-Range";
|
||||
NAME
|
||||
}
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<IfRange> {
|
||||
let etag: ::Result<EntityTag> = header::parsing::from_one_raw_str(raw);
|
||||
|
||||
@@ -217,7 +217,8 @@ macro_rules! header {
|
||||
__hyper__deref!($id => Vec<$item>);
|
||||
impl $crate::header::Header for $id {
|
||||
fn header_name() -> &'static str {
|
||||
$n
|
||||
static NAME: &'static str = $n;
|
||||
NAME
|
||||
}
|
||||
fn parse_header(raw: &[Vec<u8>]) -> $crate::Result<Self> {
|
||||
$crate::header::parsing::from_comma_delimited(raw).map($id)
|
||||
@@ -243,7 +244,8 @@ macro_rules! header {
|
||||
__hyper__deref!($id => Vec<$item>);
|
||||
impl $crate::header::Header for $id {
|
||||
fn header_name() -> &'static str {
|
||||
$n
|
||||
static NAME: &'static str = $n;
|
||||
NAME
|
||||
}
|
||||
fn parse_header(raw: &[Vec<u8>]) -> $crate::Result<Self> {
|
||||
$crate::header::parsing::from_comma_delimited(raw).map($id)
|
||||
@@ -268,7 +270,8 @@ macro_rules! header {
|
||||
__hyper__deref!($id => $value);
|
||||
impl $crate::header::Header for $id {
|
||||
fn header_name() -> &'static str {
|
||||
$n
|
||||
static NAME: &'static str = $n;
|
||||
NAME
|
||||
}
|
||||
fn parse_header(raw: &[Vec<u8>]) -> $crate::Result<Self> {
|
||||
$crate::header::parsing::from_one_raw_str(raw).map($id)
|
||||
@@ -296,7 +299,8 @@ macro_rules! header {
|
||||
}
|
||||
impl $crate::header::Header for $id {
|
||||
fn header_name() -> &'static str {
|
||||
$n
|
||||
static NAME: &'static str = $n;
|
||||
NAME
|
||||
}
|
||||
fn parse_header(raw: &[Vec<u8>]) -> $crate::Result<Self> {
|
||||
// FIXME: Return None if no item is in $id::Only
|
||||
|
||||
@@ -40,7 +40,8 @@ pub enum Pragma {
|
||||
|
||||
impl Header for Pragma {
|
||||
fn header_name() -> &'static str {
|
||||
"Pragma"
|
||||
static NAME: &'static str = "Pragma";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Pragma> {
|
||||
|
||||
@@ -52,7 +52,8 @@ __hyper__deref!(Prefer => Vec<Preference>);
|
||||
|
||||
impl Header for Prefer {
|
||||
fn header_name() -> &'static str {
|
||||
"Prefer"
|
||||
static NAME: &'static str = "Prefer";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Prefer> {
|
||||
|
||||
@@ -50,7 +50,8 @@ __hyper__deref!(PreferenceApplied => Vec<Preference>);
|
||||
|
||||
impl Header for PreferenceApplied {
|
||||
fn header_name() -> &'static str {
|
||||
"Preference-Applied"
|
||||
static NAME: &'static str = "Preference-Applied";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<PreferenceApplied> {
|
||||
|
||||
@@ -176,7 +176,8 @@ impl FromStr for ByteRangeSpec {
|
||||
impl Header for Range {
|
||||
|
||||
fn header_name() -> &'static str {
|
||||
"Range"
|
||||
static NAME: &'static str = "Range";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<Range> {
|
||||
|
||||
@@ -84,7 +84,8 @@ __hyper__deref!(SetCookie => Vec<CookiePair>);
|
||||
|
||||
impl Header for SetCookie {
|
||||
fn header_name() -> &'static str {
|
||||
"Set-Cookie"
|
||||
static NAME: &'static str = "Set-Cookie";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<SetCookie> {
|
||||
|
||||
@@ -121,7 +121,8 @@ impl FromStr for StrictTransportSecurity {
|
||||
|
||||
impl Header for StrictTransportSecurity {
|
||||
fn header_name() -> &'static str {
|
||||
"Strict-Transport-Security"
|
||||
static NAME: &'static str = "Strict-Transport-Security";
|
||||
NAME
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> ::Result<StrictTransportSecurity> {
|
||||
|
||||
Reference in New Issue
Block a user