Split common headers into a submodule and into their own files

This is a more extensible place to put them and doesn't clutter up
header/mod.rs as much as the old scheme did.

Fixes #8
This commit is contained in:
Jonathan Reem
2014-09-08 16:12:47 -07:00
parent fd6b014e7e
commit f2c09c5743
17 changed files with 727 additions and 637 deletions

59
src/header/common/mod.rs Normal file
View File

@@ -0,0 +1,59 @@
//! A Collection of Header implementations for common HTTP Headers.
//!
//! ## Mime
//!
//! Several header fields use MIME values for their contents. Keeping with the
//! strongly-typed theme, the [mime](http://seanmonstar.github.io/mime.rs) crate
//! is used, such as `ContentType(pub Mime)`.
pub use self::host::Host;
pub use self::content_length::ContentLength;
pub use self::content_type::ContentType;
pub use self::accept::Accept;
pub use self::connection::Connection;
pub use self::transfer_encoding::TransferEncoding;
pub use self::user_agent::UserAgent;
pub use self::server::Server;
pub use self::date::Date;
use std::from_str::FromStr;
use std::str::from_utf8;
/// Exposes the Host header.
pub mod host;
/// Exposes the ContentLength header.
pub mod content_length;
/// Exposes the ContentType header.
pub mod content_type;
/// Exposes the Accept header.
pub mod accept;
/// Exposes the Connection header.
pub mod connection;
/// Exposes the TransferEncoding header.
pub mod transfer_encoding;
/// Exposes the UserAgent header.
pub mod user_agent;
/// Exposes the Server header.
pub mod server;
/// Exposes the Date header.
pub mod date;
fn from_one_raw_str<T: FromStr>(raw: &[Vec<u8>]) -> Option<T> {
if raw.len() != 1 {
return None;
}
// we JUST checked that raw.len() == 1, so raw[0] WILL exist.
match from_utf8(unsafe { raw.as_slice().unsafe_get(0).as_slice() }) {
Some(s) => FromStr::from_str(s),
None => None
}
}