refactor(headers): export all headers and utils directly under header

Currently headers are exported at many places. For example you can access
`Transfer-Encoding` header at `header`, `header::common` and
`header::common::transfer_encoding`. Per discussion on IRC with
@seanmonstar and @reem, all contents of headers will be exposed at `header`
directly. Parsing utilities will be exposed at `header::parsing`. Header
macros can now be used from other crates.

This breaks much code using headers. It should use everything it needs
directly from `header::`, encodings are exposed at `header::Encoding::`,
connection options are exposed at `header::ConnectionOption`.
This commit is contained in:
Pyfisch
2015-01-20 13:04:42 +01:00
parent 7a5813b4b2
commit 8d0e5bc302
37 changed files with 223 additions and 272 deletions

View File

@@ -1,9 +1,7 @@
use header::{Header, HeaderFormat};
use std::fmt;
use std::str::FromStr;
use header::shared::util::{from_comma_delimited, fmt_comma_delimited};
use self::Encoding::{Chunked, Gzip, Deflate, Compress, EncodingExt};
use header::Encoding;
use header::parsing::{from_comma_delimited, fmt_comma_delimited};
/// The `Transfer-Encoding` header.
///
@@ -23,54 +21,6 @@ pub struct TransferEncoding(pub Vec<Encoding>);
deref!(TransferEncoding => Vec<Encoding>);
/// A value to be used with the `Transfer-Encoding` header.
///
/// Example:
///
/// ```
/// # use hyper::header::TransferEncoding;
/// # use hyper::header::transfer_encoding::Encoding::{Gzip, Chunked};
/// # use hyper::header::Headers;
/// # let mut headers = Headers::new();
/// headers.set(TransferEncoding(vec![Gzip, Chunked]));
#[derive(Clone, PartialEq, Show)]
pub enum Encoding {
/// The `chunked` encoding.
Chunked,
/// The `gzip` encoding.
Gzip,
/// The `deflate` encoding.
Deflate,
/// The `compress` encoding.
Compress,
/// Some other encoding that is less common, can be any String.
EncodingExt(String)
}
impl fmt::String for Encoding {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", match *self {
Chunked => "chunked",
Gzip => "gzip",
Deflate => "deflate",
Compress => "compress",
EncodingExt(ref s) => s.as_slice()
})
}
}
impl FromStr for Encoding {
fn from_str(s: &str) -> Option<Encoding> {
match s {
"chunked" => Some(Chunked),
"deflate" => Some(Deflate),
"gzip" => Some(Gzip),
"compress" => Some(Compress),
_ => Some(EncodingExt(s.to_string()))
}
}
}
impl Header for TransferEncoding {
fn header_name(_: Option<TransferEncoding>) -> &'static str {
"Transfer-Encoding"
@@ -89,4 +39,3 @@ impl HeaderFormat for TransferEncoding {
bench_header!(normal, TransferEncoding, { vec![b"chunked, gzip".to_vec()] });
bench_header!(ext, TransferEncoding, { vec![b"ext".to_vec()] });