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:
		| @@ -13,8 +13,8 @@ pub use net::{Fresh, Streaming}; | ||||
|  | ||||
| use HttpError::HttpIoError; | ||||
| use {HttpResult}; | ||||
| use header::common::Connection; | ||||
| use header::common::connection::{KeepAlive, Close}; | ||||
| use header::Connection; | ||||
| use header::ConnectionOption::{Close, KeepAlive}; | ||||
| use net::{NetworkListener, NetworkStream, NetworkAcceptor, | ||||
|           HttpAcceptor, HttpListener}; | ||||
| use version::HttpVersion::{Http10, Http11}; | ||||
| @@ -183,4 +183,3 @@ impl<F> Handler for F where F: Fn(Request, Response<Fresh>), F: Sync + Send { | ||||
|         (*self)(req, res) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -8,8 +8,7 @@ use std::io::net::ip::SocketAddr; | ||||
| use {HttpResult}; | ||||
| use version::{HttpVersion}; | ||||
| use method::Method::{self, Get, Head}; | ||||
| use header::Headers; | ||||
| use header::common::{ContentLength, TransferEncoding}; | ||||
| use header::{Headers, ContentLength, TransferEncoding}; | ||||
| use http::{read_request_line}; | ||||
| use http::HttpReader; | ||||
| use http::HttpReader::{SizedReader, ChunkedReader, EmptyReader}; | ||||
| @@ -74,8 +73,7 @@ impl<'a> Reader for Request<'a> { | ||||
|  | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
|     use header::common::{Host, TransferEncoding}; | ||||
|     use header::common::transfer_encoding::Encoding; | ||||
|     use header::{Host, TransferEncoding, Encoding}; | ||||
|     use mock::MockStream; | ||||
|     use super::Request; | ||||
|  | ||||
|   | ||||
| @@ -7,7 +7,6 @@ use std::io::IoResult; | ||||
| use time::now_utc; | ||||
|  | ||||
| use header; | ||||
| use header::common; | ||||
| use http::{CR, LF, LINE_ENDING, HttpWriter}; | ||||
| use http::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter}; | ||||
| use status; | ||||
| @@ -70,15 +69,15 @@ impl<'a> Response<'a, Fresh> { | ||||
|         debug!("writing head: {:?} {:?}", self.version, self.status); | ||||
|         try!(write!(&mut self.body, "{} {}{}{}", self.version, self.status, CR as char, LF as char)); | ||||
|  | ||||
|         if !self.headers.has::<common::Date>() { | ||||
|             self.headers.set(common::Date(now_utc())); | ||||
|         if !self.headers.has::<header::Date>() { | ||||
|             self.headers.set(header::Date(now_utc())); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         let mut chunked = true; | ||||
|         let mut len = 0; | ||||
|  | ||||
|         match self.headers.get::<common::ContentLength>() { | ||||
|         match self.headers.get::<header::ContentLength>() { | ||||
|             Some(cl) => { | ||||
|                 chunked = false; | ||||
|                 len = **cl; | ||||
| @@ -88,18 +87,18 @@ impl<'a> Response<'a, Fresh> { | ||||
|  | ||||
|         // cant do in match above, thanks borrowck | ||||
|         if chunked { | ||||
|             let encodings = match self.headers.get_mut::<common::TransferEncoding>() { | ||||
|                 Some(&mut common::TransferEncoding(ref mut encodings)) => { | ||||
|             let encodings = match self.headers.get_mut::<header::TransferEncoding>() { | ||||
|                 Some(&mut header::TransferEncoding(ref mut encodings)) => { | ||||
|                     //TODO: check if chunked is already in encodings. use HashSet? | ||||
|                     encodings.push(common::transfer_encoding::Encoding::Chunked); | ||||
|                     encodings.push(header::Encoding::Chunked); | ||||
|                     false | ||||
|                 }, | ||||
|                 None => true | ||||
|             }; | ||||
|  | ||||
|             if encodings { | ||||
|                 self.headers.set::<common::TransferEncoding>( | ||||
|                     common::TransferEncoding(vec![common::transfer_encoding::Encoding::Chunked])) | ||||
|                 self.headers.set::<header::TransferEncoding>( | ||||
|                     header::TransferEncoding(vec![header::Encoding::Chunked])) | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -151,4 +150,3 @@ impl<'a> Writer for Response<'a, Streaming> { | ||||
|         self.body.flush() | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user