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:
Sean McArthur
2015-03-16 15:56:38 -07:00
parent fe8c6d9914
commit 0b7169432b
3 changed files with 152 additions and 37 deletions

View 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")
}
}