Skip to content

Commit 054fd51

Browse files
committed
Merge pull request #247 from hyperium/fix-header-fmt
fix(header): fix fmt_header outputs of several headers
2 parents cfebdab + aa26665 commit 054fd51

File tree

11 files changed

+45
-62
lines changed

11 files changed

+45
-62
lines changed

src/header/common/cache_control.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub enum CacheDirective {
7272
impl fmt::String for CacheDirective {
7373
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7474
use self::CacheDirective::*;
75-
match *self {
75+
fmt::String::fmt(match *self {
7676
NoCache => "no-cache",
7777
NoStore => "no-store",
7878
NoTransform => "no-transform",
@@ -91,7 +91,7 @@ impl fmt::String for CacheDirective {
9191
Extension(ref name, None) => &name[],
9292
Extension(ref name, Some(ref arg)) => return write!(f, "{}={}", name, arg),
9393

94-
}.fmt(f)
94+
}, f)
9595
}
9696
}
9797

src/header/common/connection.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use header::{Header, HeaderFormat};
2-
use std::fmt::{self, Show};
2+
use std::fmt;
33
use std::str::FromStr;
44
use header::shared::util::{from_comma_delimited, fmt_comma_delimited};
55

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

1414
/// Values that can be in the `Connection` header.
15-
#[derive(Clone, PartialEq)]
15+
#[derive(Clone, PartialEq, Show)]
1616
pub enum ConnectionOption {
1717
/// The `keep-alive` connection value.
1818
KeepAlive,
@@ -49,12 +49,6 @@ impl fmt::String for ConnectionOption {
4949
}
5050
}
5151

52-
impl fmt::Show for ConnectionOption {
53-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
54-
self.to_string().fmt(fmt)
55-
}
56-
}
57-
5852
impl Header for Connection {
5953
fn header_name(_: Option<Connection>) -> &'static str {
6054
"Connection"

src/header/common/content_type.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use header::{Header, HeaderFormat};
2-
use std::fmt::{self, String};
2+
use std::fmt;
33
use header::shared::util::from_one_raw_str;
44
use mime::Mime;
55

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

2525
impl HeaderFormat for ContentType {
2626
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
27-
let ContentType(ref value) = *self;
28-
value.fmt(fmt)
27+
fmt::String::fmt(&self.0, fmt)
2928
}
3029
}
3130

src/header/common/date.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::{self, Show};
1+
use std::fmt;
22
use std::str::FromStr;
33
use time::Tm;
44
use header::{Header, HeaderFormat};
@@ -7,7 +7,7 @@ use header::shared::time::tm_from_str;
77

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

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

2626
impl HeaderFormat for Date {
2727
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
28-
let tm = **self;
29-
match tm.tm_utcoff {
30-
0 => tm.rfc822().fmt(fmt),
31-
_ => tm.to_utc().rfc822().fmt(fmt)
32-
}
28+
let tm = self.0;
29+
let tm = match tm.tm_utcoff {
30+
0 => tm,
31+
_ => tm.to_utc(),
32+
};
33+
fmt::String::fmt(&tm.rfc822(), fmt)
3334
}
3435
}
3536

src/header/common/expires.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::fmt::{self, Show};
1+
use std::fmt;
22
use std::str::FromStr;
33
use time::Tm;
44
use header::{Header, HeaderFormat};
55
use header::shared::util::from_one_raw_str;
66
use header::shared::time::tm_from_str;
77

88
/// The `Expires` header field.
9-
#[derive(Copy, PartialEq, Clone)]
9+
#[derive(Copy, PartialEq, Clone, Show)]
1010
pub struct Expires(pub Tm);
1111

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

2525
impl HeaderFormat for Expires {
2626
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
27-
let tm = **self;
28-
match tm.tm_utcoff {
29-
0 => tm.rfc822().fmt(fmt),
30-
_ => tm.to_utc().rfc822().fmt(fmt)
31-
}
27+
let tm = self.0;
28+
let tm = match tm.tm_utcoff {
29+
0 => tm,
30+
_ => tm.to_utc(),
31+
};
32+
fmt::String::fmt(&tm.rfc822(), fmt)
3233
}
3334
}
3435

src/header/common/if_modified_since.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::fmt::{self, Show};
1+
use std::fmt;
22
use std::str::FromStr;
33
use time::Tm;
44
use header::{Header, HeaderFormat};
55
use header::shared::util::from_one_raw_str;
66
use header::shared::time::tm_from_str;
77

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

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

2525
impl HeaderFormat for IfModifiedSince {
2626
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
27-
let tm = **self;
28-
match tm.tm_utcoff {
29-
0 => tm.rfc822().fmt(fmt),
30-
_ => tm.to_utc().rfc822().fmt(fmt)
31-
}
27+
let tm = self.0;
28+
let tm = match tm.tm_utcoff {
29+
0 => tm,
30+
_ => tm.to_utc(),
31+
};
32+
fmt::String::fmt(&tm.rfc822(), fmt)
3233
}
3334
}
3435

src/header/common/last_modified.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::fmt::{self, Show};
1+
use std::fmt;
22
use std::str::FromStr;
33
use time::Tm;
44
use header::{Header, HeaderFormat};
55
use header::shared::util::from_one_raw_str;
66
use header::shared::time::tm_from_str;
77

88
/// The `LastModified` header field.
9-
#[derive(Copy, PartialEq, Clone)]
9+
#[derive(Copy, PartialEq, Clone, Show)]
1010
pub struct LastModified(pub Tm);
1111

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

2525
impl HeaderFormat for LastModified {
2626
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
27-
let tm = **self;
28-
match tm.tm_utcoff {
29-
0 => tm.rfc822().fmt(fmt),
30-
_ => tm.to_utc().rfc822().fmt(fmt)
31-
}
27+
let tm = self.0;
28+
let tm = match tm.tm_utcoff {
29+
0 => tm,
30+
_ => tm.to_utc(),
31+
};
32+
fmt::String::fmt(&tm.rfc822(), fmt)
3233
}
3334
}
3435

src/header/common/location.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use header::{Header, HeaderFormat};
2-
use std::fmt::{self, Show};
2+
use std::fmt;
33
use header::shared::util::from_one_raw_str;
44

55
/// The `Location` header.
@@ -30,8 +30,7 @@ impl Header for Location {
3030

3131
impl HeaderFormat for Location {
3232
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
33-
let Location(ref value) = *self;
34-
value.fmt(fmt)
33+
fmt.write_str(&*self.0)
3534
}
3635
}
3736

src/header/common/server.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use header::{Header, HeaderFormat};
2-
use std::fmt::{self, Show};
2+
use std::fmt;
33
use header::shared::util::from_one_raw_str;
44

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

2323
impl HeaderFormat for Server {
2424
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
25-
let Server(ref value) = *self;
26-
value.fmt(fmt)
25+
fmt.write_str(&*self.0)
2726
}
2827
}
2928

src/header/common/transfer_encoding.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ deref!(TransferEncoding => Vec<Encoding>);
3333
/// # use hyper::header::Headers;
3434
/// # let mut headers = Headers::new();
3535
/// headers.set(TransferEncoding(vec![Gzip, Chunked]));
36-
#[derive(Clone, PartialEq)]
36+
#[derive(Clone, PartialEq, Show)]
3737
pub enum Encoding {
3838
/// The `chunked` encoding.
3939
Chunked,
@@ -59,12 +59,6 @@ impl fmt::String for Encoding {
5959
}
6060
}
6161

62-
impl fmt::Show for Encoding {
63-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
64-
self.to_string().fmt(fmt)
65-
}
66-
}
67-
6862
impl FromStr for Encoding {
6963
fn from_str(s: &str) -> Option<Encoding> {
7064
match s {

0 commit comments

Comments
 (0)