feat(server): add Expect 100-continue support
Adds a new method to `Handler`, with a default implementation of always responding with a `100 Continue` when sent an expectation. Closes #369
This commit is contained in:
		
							
								
								
									
										37
									
								
								src/header/common/expect.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/header/common/expect.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| use std::fmt; | ||||
|  | ||||
| use header::{Header, HeaderFormat}; | ||||
|  | ||||
| /// The `Expect` header. | ||||
| /// | ||||
| /// > The "Expect" header field in a request indicates a certain set of | ||||
| /// > behaviors (expectations) that need to be supported by the server in | ||||
| /// > order to properly handle this request.  The only such expectation | ||||
| /// > defined by this specification is 100-continue. | ||||
| /// > | ||||
| /// >    Expect  = "100-continue" | ||||
| #[derive(Copy, Clone, PartialEq, Debug)] | ||||
| pub enum Expect { | ||||
|     /// The value `100-continue`. | ||||
|     Continue | ||||
| } | ||||
|  | ||||
| impl Header for Expect { | ||||
|     fn header_name() -> &'static str { | ||||
|         "Expect" | ||||
|     } | ||||
|  | ||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<Expect> { | ||||
|         if &[b"100-continue"] == raw { | ||||
|             Some(Expect::Continue) | ||||
|         } else { | ||||
|             None | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl HeaderFormat for Expect { | ||||
|     fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         f.write_str("100-continue") | ||||
|     } | ||||
| } | ||||
| @@ -20,6 +20,7 @@ pub use self::content_type::ContentType; | ||||
| pub use self::cookie::Cookie; | ||||
| pub use self::date::Date; | ||||
| pub use self::etag::Etag; | ||||
| pub use self::expect::Expect; | ||||
| pub use self::expires::Expires; | ||||
| pub use self::host::Host; | ||||
| pub use self::if_match::IfMatch; | ||||
| @@ -160,6 +161,7 @@ mod content_length; | ||||
| mod content_type; | ||||
| mod date; | ||||
| mod etag; | ||||
| mod expect; | ||||
| mod expires; | ||||
| mod host; | ||||
| mod if_match; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user