Skip to content

Commit f797d3b

Browse files
pietroalbinijplatte
authored andcommitted
links: update logic to the new headers API
1 parent 218abf3 commit f797d3b

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/common/link.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ use std::ascii::AsciiExt;
99
use mime::Mime;
1010
use language_tags::LanguageTag;
1111

12-
use parsing;
13-
use {Header, Raw};
14-
1512
/// The `Link` header, defined in
1613
/// [RFC5988](http://tools.ietf.org/html/rfc5988#section-5)
1714
///
@@ -387,18 +384,24 @@ impl LinkValue {
387384
// Trait implementations
388385
////////////////////////////////////////////////////////////////////////////////
389386

390-
impl Header for Link {
391-
fn header_name() -> &'static str {
392-
static NAME: &'static str = "Link";
393-
NAME
387+
impl ::Header for Link {
388+
fn name() -> &'static ::HeaderName {
389+
&::http::header::LINK
394390
}
395391

396-
fn parse_header(raw: &Raw) -> Result<Link, ::Error> {
392+
fn decode<'i, I>(values: &mut I) -> Result<Self, ::Error>
393+
where
394+
I: Iterator<Item = &'i ::HeaderValue>,
395+
{
397396
// If more that one `Link` headers are present in a request's
398397
// headers they are combined in a single `Link` header containing
399398
// all the `link-value`s present in each of those `Link` headers.
400-
raw.iter()
401-
.map(parsing::from_raw_str::<Link>)
399+
values
400+
.map(|line| {
401+
line.to_str()
402+
.map_err(|_| ::Error::invalid())
403+
.and_then(|line| Link::from_str(line))
404+
})
402405
.fold(None, |p, c| {
403406
match (p, c) {
404407
(None, c) => Some(c),
@@ -414,14 +417,23 @@ impl Header for Link {
414417
.unwrap_or(Err(::Error::invalid()))
415418
}
416419

417-
fn fmt_header(&self, f: &mut ::Formatter) -> fmt::Result {
418-
f.fmt_line(self)
420+
fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
421+
values.extend(std::iter::once(::HeaderValue::from_str(&self.to_string()).unwrap()));
419422
}
420423
}
421424

422425
impl fmt::Display for Link {
423426
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
424-
fmt_delimited(f, self.values.as_slice(), ", ", ("", ""))
427+
let mut first = true;
428+
for value in &self.values {
429+
if !first {
430+
write!(f, ", ")?;
431+
}
432+
first = false;
433+
434+
write!(f, "{}", value)?;
435+
}
436+
Ok(())
425437
}
426438
}
427439

0 commit comments

Comments
 (0)