1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 18:37:41 +02:00

simplify httpresponse release

This commit is contained in:
Nikolay Kim
2018-03-20 15:51:19 -07:00
parent ee7d58dd7f
commit 70caa2552b
2 changed files with 47 additions and 41 deletions

View File

@ -490,6 +490,8 @@ impl Reader {
fn parse_message<H>(buf: &mut BytesMut, settings: &WorkerSettings<H>)
-> Poll<(HttpRequest, Option<PayloadInfo>), ParseError> {
// Parse http message
let mut has_te = false;
let mut has_upgrade = false;
let msg = {
let bytes_ptr = buf.as_ref().as_ptr() as usize;
let mut headers: [httparse::Header; MAX_HEADERS] =
@ -500,7 +502,7 @@ impl Reader {
let mut req = httparse::Request::new(&mut headers);
match req.parse(b)? {
httparse::Status::Complete(len) => {
let method = Method::try_from(req.method.unwrap())
let method = Method::from_bytes(req.method.unwrap().as_bytes())
.map_err(|_| ParseError::Method)?;
//let path = req.path.unwrap();
//let path_start = path.as_ptr() as usize - bytes_ptr;
@ -527,7 +529,9 @@ impl Reader {
{
let msg_mut = msg.get_mut();
for header in headers[..headers_len].iter() {
if let Ok(name) = HeaderName::try_from(header.name) {
if let Ok(name) = HeaderName::from_bytes(header.name.as_bytes()) {
has_te = has_te || name == header::TRANSFER_ENCODING;
has_upgrade = has_upgrade || name == header::UPGRADE;
let v_start = header.value.as_ptr() as usize - bytes_ptr;
let v_end = v_start + header.value.len();
let value = unsafe {
@ -540,8 +544,6 @@ impl Reader {
}
msg_mut.uri = path;
//msg_mut.uri = Uri::from_shared(
//slice.slice(path.0, path.1)).map_err(ParseError::Uri)?;
msg_mut.method = method;
msg_mut.version = version;
}
@ -563,12 +565,10 @@ impl Reader {
debug!("illegal Content-Length: {:?}", len);
return Err(ParseError::Header)
}
} else if chunked(&msg.get_mut().headers)? {
} else if has_te && chunked(&msg.get_mut().headers)? {
// Chunked encoding
Some(Decoder::chunked())
} else if msg.get_ref().headers.contains_key(header::UPGRADE) ||
msg.get_ref().method == Method::CONNECT
{
} else if has_upgrade || msg.get_ref().method == Method::CONNECT {
Some(Decoder::eof())
} else {
None