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:
		
							
								
								
									
										45
									
								
								src/header/common/connection.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/header/common/connection.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| use header::Header; | ||||
| use std::fmt::{mod, Show}; | ||||
| use super::from_one_raw_str; | ||||
| use std::from_str::FromStr; | ||||
|  | ||||
| /// The `Connection` header. | ||||
| /// | ||||
| /// Describes whether the socket connection should be closed or reused after | ||||
| /// this request/response is completed. | ||||
| #[deriving(Clone, PartialEq, Show)] | ||||
| pub enum Connection { | ||||
|     /// The `keep-alive` connection value. | ||||
|     KeepAlive, | ||||
|     /// The `close` connection value. | ||||
|     Close | ||||
| } | ||||
|  | ||||
| impl FromStr for Connection { | ||||
|     fn from_str(s: &str) -> Option<Connection> { | ||||
|         debug!("Connection::from_str =? {}", s); | ||||
|         match s { | ||||
|             "keep-alive" => Some(KeepAlive), | ||||
|             "close" => Some(Close), | ||||
|             _ => None | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Header for Connection { | ||||
|     fn header_name(_: Option<Connection>) -> &'static str { | ||||
|         "connection" | ||||
|     } | ||||
|  | ||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<Connection> { | ||||
|         from_one_raw_str(raw) | ||||
|     } | ||||
|  | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         match *self { | ||||
|             KeepAlive => "keep-alive", | ||||
|             Close => "close", | ||||
|         }.fmt(fmt) | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user