1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-19 04:15:38 +02:00

add expect: 100-continue support #141

This commit is contained in:
Nikolay Kim
2019-04-05 16:46:44 -07:00
parent 02fcaca3da
commit fbedaec661
18 changed files with 554 additions and 156 deletions

View File

@@ -51,6 +51,8 @@ pub(crate) enum PayloadLength {
pub(crate) trait MessageType: Sized {
fn set_connection_type(&mut self, ctype: Option<ConnectionType>);
fn set_expect(&mut self);
fn headers_mut(&mut self) -> &mut HeaderMap;
fn decode(src: &mut BytesMut) -> Result<Option<(Self, PayloadType)>, ParseError>;
@@ -62,6 +64,7 @@ pub(crate) trait MessageType: Sized {
) -> Result<PayloadLength, ParseError> {
let mut ka = None;
let mut has_upgrade = false;
let mut expect = false;
let mut chunked = false;
let mut content_length = None;
@@ -126,6 +129,12 @@ pub(crate) trait MessageType: Sized {
}
}
}
header::EXPECT => {
let bytes = value.as_bytes();
if bytes.len() >= 4 && &bytes[0..4] == b"100-" {
expect = true;
}
}
_ => (),
}
@@ -136,6 +145,9 @@ pub(crate) trait MessageType: Sized {
}
}
self.set_connection_type(ka);
if expect {
self.set_expect()
}
// https://tools.ietf.org/html/rfc7230#section-3.3.3
if chunked {
@@ -163,6 +175,10 @@ impl MessageType for Request {
}
}
fn set_expect(&mut self) {
self.head_mut().set_expect();
}
fn headers_mut(&mut self) -> &mut HeaderMap {
&mut self.head_mut().headers
}
@@ -235,6 +251,8 @@ impl MessageType for ResponseHead {
}
}
fn set_expect(&mut self) {}
fn headers_mut(&mut self) -> &mut HeaderMap {
&mut self.headers
}