1 use bytes::BytesMut; 2 use http::{HeaderMap, Method}; 3 4 use proto::{MessageHead, BodyLength, DecodedLength}; 5 6 pub(crate) use self::conn::Conn; 7 pub(crate) use self::dispatch::Dispatcher; 8 pub use self::decode::Decoder; 9 pub use self::encode::{EncodedBuf, Encoder}; 10 pub use self::io::Cursor; //TODO: move out of h1::io 11 pub use self::io::MINIMUM_MAX_BUFFER_SIZE; 12 13 mod conn; 14 pub(super) mod date; 15 mod decode; 16 pub(crate) mod dispatch; 17 mod encode; 18 mod io; 19 mod role; 20 21 22 pub(crate) type ServerTransaction = role::Server; 23 pub(crate) type ClientTransaction = role::Client; 24 25 pub(crate) trait Http1Transaction { 26 type Incoming; 27 type Outgoing: Default; 28 const LOG: &'static str; parse(bytes: &mut BytesMut, ctx: ParseContext) -> ParseResult<Self::Incoming>29 fn parse(bytes: &mut BytesMut, ctx: ParseContext) -> ParseResult<Self::Incoming>; encode(enc: Encode<Self::Outgoing>, dst: &mut Vec<u8>) -> ::Result<Encoder>30 fn encode(enc: Encode<Self::Outgoing>, dst: &mut Vec<u8>) -> ::Result<Encoder>; 31 on_error(err: &::Error) -> Option<MessageHead<Self::Outgoing>>32 fn on_error(err: &::Error) -> Option<MessageHead<Self::Outgoing>>; 33 is_client() -> bool34 fn is_client() -> bool { 35 !Self::is_server() 36 } 37 is_server() -> bool38 fn is_server() -> bool { 39 !Self::is_client() 40 } 41 should_error_on_parse_eof() -> bool42 fn should_error_on_parse_eof() -> bool { 43 Self::is_client() 44 } 45 should_read_first() -> bool46 fn should_read_first() -> bool { 47 Self::is_server() 48 } 49 update_date()50 fn update_date() {} 51 } 52 53 /// Result newtype for Http1Transaction::parse. 54 pub(crate) type ParseResult<T> = Result<Option<ParsedMessage<T>>, ::error::Parse>; 55 56 #[derive(Debug)] 57 pub(crate) struct ParsedMessage<T> { 58 head: MessageHead<T>, 59 decode: DecodedLength, 60 expect_continue: bool, 61 keep_alive: bool, 62 wants_upgrade: bool, 63 } 64 65 pub(crate) struct ParseContext<'a> { 66 cached_headers: &'a mut Option<HeaderMap>, 67 req_method: &'a mut Option<Method>, 68 } 69 70 /// Passed to Http1Transaction::encode 71 pub(crate) struct Encode<'a, T: 'a> { 72 head: &'a mut MessageHead<T>, 73 body: Option<BodyLength>, 74 keep_alive: bool, 75 req_method: &'a mut Option<Method>, 76 title_case_headers: bool, 77 } 78 79