Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn handle(_r: Request, res: Response) {
struct Foo;

impl hyper::header::Header for Foo {
fn header_name(_: Option<Foo>) -> &'static str {
fn header_name() -> &'static str {
"x-foo"
}
fn parse_header(_: &[Vec<u8>]) -> Option<Foo> {
Expand Down
2 changes: 1 addition & 1 deletion benches/client_mock_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Writer for MockStream {
struct Foo;

impl hyper::header::Header for Foo {
fn header_name(_: Option<Foo>) -> &'static str {
fn header_name() -> &'static str {
"x-foo"
}
fn parse_header(_: &[Vec<u8>]) -> Option<Foo> {
Expand Down
2 changes: 1 addition & 1 deletion src/header/common/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Accept(pub Vec<header::QualityItem<mime::Mime>>);
deref!(Accept => Vec<header::QualityItem<mime::Mime>>);

impl header::Header for Accept {
fn header_name(_: Option<Accept>) -> &'static str {
fn header_name() -> &'static str {
"Accept"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/access_control/allow_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct AccessControlAllowHeaders(pub Vec<String>);

impl header::Header for AccessControlAllowHeaders {
#[inline]
fn header_name(_: Option<AccessControlAllowHeaders>) -> &'static str {
fn header_name() -> &'static str {
"Access-Control-Allow-Headers"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/access_control/allow_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct AccessControlAllowMethods(pub Vec<method::Method>);

impl header::Header for AccessControlAllowMethods {
#[inline]
fn header_name(_: Option<AccessControlAllowMethods>) -> &'static str {
fn header_name() -> &'static str {
"Access-Control-Allow-Methods"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/access_control/allow_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum AccessControlAllowOrigin {

impl header::Header for AccessControlAllowOrigin {
#[inline]
fn header_name(_: Option<AccessControlAllowOrigin>) -> &'static str {
fn header_name() -> &'static str {
"Access-Control-Allow-Origin"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/access_control/max_age.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct AccessControlMaxAge(pub u32);

impl header::Header for AccessControlMaxAge {
#[inline]
fn header_name(_: Option<AccessControlMaxAge>) -> &'static str {
fn header_name() -> &'static str {
"Access-Control-Max-Age"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/access_control/request_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct AccessControlRequestHeaders(pub Vec<String>);

impl header::Header for AccessControlRequestHeaders {
#[inline]
fn header_name(_: Option<AccessControlRequestHeaders>) -> &'static str {
fn header_name() -> &'static str {
"Access-Control-Request-Headers"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/access_control/request_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct AccessControlRequestMethod(pub Method);

impl header::Header for AccessControlRequestMethod {
#[inline]
fn header_name(_: Option<AccessControlRequestMethod>) -> &'static str {
fn header_name() -> &'static str {
"Access-Control-Request-Method"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/allow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Allow(pub Vec<Method>);
deref!(Allow => Vec<Method>);

impl Header for Allow {
fn header_name(_: Option<Allow>) -> &'static str {
fn header_name() -> &'static str {
"Allow"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<S: Scheme> DerefMut for Authorization<S> {
}

impl<S: Scheme> Header for Authorization<S> {
fn header_name(_: Option<Authorization<S>>) -> &'static str {
fn header_name() -> &'static str {
"Authorization"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/cache_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct CacheControl(pub Vec<CacheDirective>);
deref!(CacheControl => Vec<CacheDirective>);

impl Header for CacheControl {
fn header_name(_: Option<CacheControl>) -> &'static str {
fn header_name() -> &'static str {
"Cache-Control"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl fmt::String for ConnectionOption {
}

impl Header for Connection {
fn header_name(_: Option<Connection>) -> &'static str {
fn header_name() -> &'static str {
"Connection"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/content_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct ContentLength(pub u64);
deref!(ContentLength => u64);

impl Header for ContentLength {
fn header_name(_: Option<ContentLength>) -> &'static str {
fn header_name() -> &'static str {
"Content-Length"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/content_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct ContentType(pub Mime);
deref!(ContentType => Mime);

impl Header for ContentType {
fn header_name(_: Option<ContentType>) -> &'static str {
fn header_name() -> &'static str {
"Content-Type"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Cookies(pub Vec<Cookie>);
deref!(Cookies => Vec<Cookie>);

impl Header for Cookies {
fn header_name(_: Option<Cookies>) -> &'static str {
fn header_name() -> &'static str {
"Cookie"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Date(pub Tm);
deref!(Date => Tm);

impl Header for Date {
fn header_name(_: Option<Date>) -> &'static str {
fn header_name() -> &'static str {
"Date"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/etag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Etag {
}

impl Header for Etag {
fn header_name(_: Option<Etag>) -> &'static str {
fn header_name() -> &'static str {
"Etag"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/expires.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Expires(pub Tm);
deref!(Expires => Tm);

impl Header for Expires {
fn header_name(_: Option<Expires>) -> &'static str {
fn header_name() -> &'static str {
"Expires"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Host {
}

impl Header for Host {
fn header_name(_: Option<Host>) -> &'static str {
fn header_name() -> &'static str {
"Host"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/if_modified_since.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct IfModifiedSince(pub Tm);
deref!(IfModifiedSince => Tm);

impl Header for IfModifiedSince {
fn header_name(_: Option<IfModifiedSince>) -> &'static str {
fn header_name() -> &'static str {
"If-Modified-Since"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/last_modified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct LastModified(pub Tm);
deref!(LastModified => Tm);

impl Header for LastModified {
fn header_name(_: Option<LastModified>) -> &'static str {
fn header_name() -> &'static str {
"Last-Modified"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Location(pub String);
deref!(Location => String);

impl Header for Location {
fn header_name(_: Option<Location>) -> &'static str {
fn header_name() -> &'static str {
"Location"
}

Expand Down
4 changes: 2 additions & 2 deletions src/header/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ macro_rules! impl_list_header(
deref!($from => $item);

impl header::Header for $from {
fn header_name(_: Option<$from>) -> &'static str {
fn header_name() -> &'static str {
$name
}

Expand Down Expand Up @@ -116,7 +116,7 @@ macro_rules! impl_header(
deref!($from => $item);

impl header::Header for $from {
fn header_name(_: Option<$from>) -> &'static str {
fn header_name() -> &'static str {
$name
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/referer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Referer(pub String);
deref!(Referer => String);

impl Header for Referer {
fn header_name(_: Option<Referer>) -> &'static str {
fn header_name() -> &'static str {
"Referer"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/set_cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct SetCookie(pub Vec<Cookie>);
deref!(SetCookie => Vec<Cookie>);

impl Header for SetCookie {
fn header_name(_: Option<SetCookie>) -> &'static str {
fn header_name() -> &'static str {
"Set-Cookie"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/transfer_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct TransferEncoding(pub Vec<Encoding>);
deref!(TransferEncoding => Vec<Encoding>);

impl Header for TransferEncoding {
fn header_name(_: Option<TransferEncoding>) -> &'static str {
fn header_name() -> &'static str {
"Transfer-Encoding"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl fmt::String for Protocol {
}

impl Header for Upgrade {
fn header_name(_: Option<Upgrade>) -> &'static str {
fn header_name() -> &'static str {
"Upgrade"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct UserAgent(pub String);
deref!(UserAgent => String);

impl Header for UserAgent {
fn header_name(_: Option<UserAgent>) -> &'static str {
fn header_name() -> &'static str {
"User-Agent"
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/vary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Vary {
}

impl Header for Vary {
fn header_name(_: Option<Vary>) -> &'static str {
fn header_name() -> &'static str {
"Vary"
}

Expand Down
14 changes: 7 additions & 7 deletions src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ type HeaderName = UniCase<CowString<'static>>;
pub trait Header: Clone + Any + Send + Sync {
/// Returns the name of the header field this belongs to.
///
/// The market `Option` is to hint to the type system which implementation
/// to call. This can be done away with once UFCS arrives.
fn header_name(marker: Option<Self>) -> &'static str;
/// This will become an associated constant once available.
fn header_name() -> &'static str;
/// Parse a header from a raw stream of bytes.
///
/// It's possible that a request can include a header field more than once,
Expand Down Expand Up @@ -107,8 +106,9 @@ impl Clone for Box<HeaderFormat + Send + Sync> {
}
}

#[inline]
fn header_name<T: Header>() -> &'static str {
let name = Header::header_name(None::<T>);
let name = <T as Header>::header_name();
name
}

Expand Down Expand Up @@ -246,7 +246,7 @@ impl Headers {
/// Removes a header from the map, if one existed.
/// Returns true if a header has been removed.
pub fn remove<H: Header + HeaderFormat>(&mut self) -> bool {
self.data.remove(&UniCase(Borrowed(Header::header_name(None::<H>)))).is_some()
self.data.remove(&UniCase(Borrowed(header_name::<H>()))).is_some()
}

/// Returns an iterator over the header fields.
Expand Down Expand Up @@ -559,7 +559,7 @@ mod tests {
struct CrazyLength(Option<bool>, usize);

impl Header for CrazyLength {
fn header_name(_: Option<CrazyLength>) -> &'static str {
fn header_name() -> &'static str {
"content-length"
}
fn parse_header(raw: &[Vec<u8>]) -> Option<CrazyLength> {
Expand Down Expand Up @@ -678,7 +678,7 @@ mod tests {
headers.set(ContentLength(11));
for header in headers.iter() {
assert!(header.is::<ContentLength>());
assert_eq!(header.name(), Header::header_name(None::<ContentLength>));
assert_eq!(header.name(), <ContentLength as Header>::header_name());
assert_eq!(header.value(), Some(&ContentLength(11)));
assert_eq!(header.value_string(), "11".to_string());
}
Expand Down