refactor(header): change Header::fmt_header to take a header::Formatter
The `header::Formatter` ensures that a formatted header is written to a line, and allows for headers that require multiple lines. The only header to specifically require this is `Set-Cookie`. BREAKING CHANGE: The `fmt_header` method has changed to take a different formatter. In most cases, if your header also implements `fmt::Display`, you can just call `f.fmt_line(self)`.
This commit is contained in:
@@ -4,7 +4,7 @@ use std::fmt;
|
||||
use std::str::from_utf8;
|
||||
|
||||
use super::cell::{OptCell, PtrMapCell};
|
||||
use header::{Header, MultilineFormatter, Multi, raw, Raw};
|
||||
use header::{Header, Formatter, Multi, raw, Raw};
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -47,7 +47,7 @@ impl Item {
|
||||
}
|
||||
|
||||
let mut raw = raw::new();
|
||||
self.write_h1(&mut MultilineFormatter(Multi::Raw(&mut raw))).expect("fmt failed");
|
||||
self.write_h1(&mut Formatter(Multi::Raw(&mut raw))).expect("fmt failed");
|
||||
self.raw.set(raw);
|
||||
|
||||
self.raw.as_ref().unwrap()
|
||||
@@ -93,7 +93,7 @@ impl Item {
|
||||
}.map(|typed| unsafe { typed.downcast_unchecked() })
|
||||
}
|
||||
|
||||
pub fn write_h1(&self, f: &mut MultilineFormatter) -> fmt::Result {
|
||||
pub fn write_h1(&self, f: &mut Formatter) -> fmt::Result {
|
||||
match *self.raw {
|
||||
Some(ref raw) => {
|
||||
for part in raw.iter() {
|
||||
@@ -111,7 +111,7 @@ impl Item {
|
||||
},
|
||||
None => {
|
||||
let typed = unsafe { self.typed.one() };
|
||||
typed.fmt_multi_header(f)
|
||||
typed.fmt_header(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user