Skip to content

Commit

Permalink
fix(header): fix fmt_header outputs of several headers
Browse files Browse the repository at this point in the history
Closes #246
  • Loading branch information
seanmonstar committed Jan 13, 2015
1 parent cfebdab commit aa26665
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/header/common/cache_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub enum CacheDirective {
impl fmt::String for CacheDirective {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::CacheDirective::*;
match *self {
fmt::String::fmt(match *self {
NoCache => "no-cache",
NoStore => "no-store",
NoTransform => "no-transform",
Expand All @@ -91,7 +91,7 @@ impl fmt::String for CacheDirective {
Extension(ref name, None) => &name[],
Extension(ref name, Some(ref arg)) => return write!(f, "{}={}", name, arg),

}.fmt(f)
}, f)
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/header/common/connection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use header::{Header, HeaderFormat};
use std::fmt::{self, Show};
use std::fmt;
use std::str::FromStr;
use header::shared::util::{from_comma_delimited, fmt_comma_delimited};

Expand All @@ -12,7 +12,7 @@ pub struct Connection(pub Vec<ConnectionOption>);
deref!(Connection => Vec<ConnectionOption>);

/// Values that can be in the `Connection` header.
#[derive(Clone, PartialEq)]
#[derive(Clone, PartialEq, Show)]
pub enum ConnectionOption {
/// The `keep-alive` connection value.
KeepAlive,
Expand Down Expand Up @@ -49,12 +49,6 @@ impl fmt::String for ConnectionOption {
}
}

impl fmt::Show for ConnectionOption {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt)
}
}

impl Header for Connection {
fn header_name(_: Option<Connection>) -> &'static str {
"Connection"
Expand Down
5 changes: 2 additions & 3 deletions src/header/common/content_type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use header::{Header, HeaderFormat};
use std::fmt::{self, String};
use std::fmt;
use header::shared::util::from_one_raw_str;
use mime::Mime;

Expand All @@ -24,8 +24,7 @@ impl Header for ContentType {

impl HeaderFormat for ContentType {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let ContentType(ref value) = *self;
value.fmt(fmt)
fmt::String::fmt(&self.0, fmt)
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/header/common/date.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::{self, Show};
use std::fmt;
use std::str::FromStr;
use time::Tm;
use header::{Header, HeaderFormat};
Expand All @@ -7,7 +7,7 @@ use header::shared::time::tm_from_str;

// Egh, replace as soon as something better than time::Tm exists.
/// The `Date` header field.
#[derive(Copy, PartialEq, Clone)]
#[derive(Copy, PartialEq, Clone, Show)]
pub struct Date(pub Tm);

deref!(Date => Tm);
Expand All @@ -25,11 +25,12 @@ impl Header for Date {

impl HeaderFormat for Date {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let tm = **self;
match tm.tm_utcoff {
0 => tm.rfc822().fmt(fmt),
_ => tm.to_utc().rfc822().fmt(fmt)
}
let tm = self.0;
let tm = match tm.tm_utcoff {
0 => tm,
_ => tm.to_utc(),
};
fmt::String::fmt(&tm.rfc822(), fmt)
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/header/common/expires.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fmt::{self, Show};
use std::fmt;
use std::str::FromStr;
use time::Tm;
use header::{Header, HeaderFormat};
use header::shared::util::from_one_raw_str;
use header::shared::time::tm_from_str;

/// The `Expires` header field.
#[derive(Copy, PartialEq, Clone)]
#[derive(Copy, PartialEq, Clone, Show)]
pub struct Expires(pub Tm);

deref!(Expires => Tm);
Expand All @@ -24,11 +24,12 @@ impl Header for Expires {

impl HeaderFormat for Expires {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let tm = **self;
match tm.tm_utcoff {
0 => tm.rfc822().fmt(fmt),
_ => tm.to_utc().rfc822().fmt(fmt)
}
let tm = self.0;
let tm = match tm.tm_utcoff {
0 => tm,
_ => tm.to_utc(),
};
fmt::String::fmt(&tm.rfc822(), fmt)
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/header/common/if_modified_since.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fmt::{self, Show};
use std::fmt;
use std::str::FromStr;
use time::Tm;
use header::{Header, HeaderFormat};
use header::shared::util::from_one_raw_str;
use header::shared::time::tm_from_str;

/// The `If-Modified-Since` header field.
#[derive(Copy, PartialEq, Clone)]
#[derive(Copy, PartialEq, Clone, Show)]
pub struct IfModifiedSince(pub Tm);

deref!(IfModifiedSince => Tm);
Expand All @@ -24,11 +24,12 @@ impl Header for IfModifiedSince {

impl HeaderFormat for IfModifiedSince {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let tm = **self;
match tm.tm_utcoff {
0 => tm.rfc822().fmt(fmt),
_ => tm.to_utc().rfc822().fmt(fmt)
}
let tm = self.0;
let tm = match tm.tm_utcoff {
0 => tm,
_ => tm.to_utc(),
};
fmt::String::fmt(&tm.rfc822(), fmt)
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/header/common/last_modified.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fmt::{self, Show};
use std::fmt;
use std::str::FromStr;
use time::Tm;
use header::{Header, HeaderFormat};
use header::shared::util::from_one_raw_str;
use header::shared::time::tm_from_str;

/// The `LastModified` header field.
#[derive(Copy, PartialEq, Clone)]
#[derive(Copy, PartialEq, Clone, Show)]
pub struct LastModified(pub Tm);

deref!(LastModified => Tm);
Expand All @@ -24,11 +24,12 @@ impl Header for LastModified {

impl HeaderFormat for LastModified {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let tm = **self;
match tm.tm_utcoff {
0 => tm.rfc822().fmt(fmt),
_ => tm.to_utc().rfc822().fmt(fmt)
}
let tm = self.0;
let tm = match tm.tm_utcoff {
0 => tm,
_ => tm.to_utc(),
};
fmt::String::fmt(&tm.rfc822(), fmt)
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/header/common/location.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use header::{Header, HeaderFormat};
use std::fmt::{self, Show};
use std::fmt;
use header::shared::util::from_one_raw_str;

/// The `Location` header.
Expand Down Expand Up @@ -30,8 +30,7 @@ impl Header for Location {

impl HeaderFormat for Location {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let Location(ref value) = *self;
value.fmt(fmt)
fmt.write_str(&*self.0)
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/header/common/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use header::{Header, HeaderFormat};
use std::fmt::{self, Show};
use std::fmt;
use header::shared::util::from_one_raw_str;

/// The `Server` header field.
Expand All @@ -22,8 +22,7 @@ impl Header for Server {

impl HeaderFormat for Server {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let Server(ref value) = *self;
value.fmt(fmt)
fmt.write_str(&*self.0)
}
}

Expand Down
8 changes: 1 addition & 7 deletions src/header/common/transfer_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ deref!(TransferEncoding => Vec<Encoding>);
/// # use hyper::header::Headers;
/// # let mut headers = Headers::new();
/// headers.set(TransferEncoding(vec![Gzip, Chunked]));
#[derive(Clone, PartialEq)]
#[derive(Clone, PartialEq, Show)]
pub enum Encoding {
/// The `chunked` encoding.
Chunked,
Expand All @@ -59,12 +59,6 @@ impl fmt::String for Encoding {
}
}

impl fmt::Show for Encoding {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt)
}
}

impl FromStr for Encoding {
fn from_str(s: &str) -> Option<Encoding> {
match s {
Expand Down
10 changes: 2 additions & 8 deletions src/header/common/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use header::{Header, HeaderFormat};
use std::fmt::{self, Show};
use std::fmt;
use std::str::FromStr;
use header::shared::util::{from_comma_delimited, fmt_comma_delimited};

Expand All @@ -12,7 +12,7 @@ pub struct Upgrade(pub Vec<Protocol>);
deref!(Upgrade => Vec<Protocol>);

/// Protocol values that can appear in the Upgrade header.
#[derive(Clone, PartialEq)]
#[derive(Clone, PartialEq, Show)]
pub enum Protocol {
/// The websocket protocol.
WebSocket,
Expand All @@ -38,12 +38,6 @@ impl fmt::String for Protocol {
}
}

impl fmt::Show for Protocol {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt)
}
}

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

0 comments on commit aa26665

Please sign in to comment.