mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 09:42:40 +01:00
simplify h1 parse
This commit is contained in:
parent
1fe4315c94
commit
6d792d9948
@ -145,7 +145,9 @@ impl HttpResponseParser {
|
|||||||
// convert headers
|
// convert headers
|
||||||
let mut hdrs = HeaderMap::new();
|
let mut hdrs = HeaderMap::new();
|
||||||
for header in headers[..headers_len].iter() {
|
for header in headers[..headers_len].iter() {
|
||||||
if let Ok(name) = HeaderName::try_from(header.name) {
|
let n_start = header.name.as_ptr() as usize - bytes_ptr;
|
||||||
|
let n_end = n_start + header.name.len();
|
||||||
|
if let Ok(name) = HeaderName::try_from(slice.slice(n_start, n_end)) {
|
||||||
let v_start = header.value.as_ptr() as usize - bytes_ptr;
|
let v_start = header.value.as_ptr() as usize - bytes_ptr;
|
||||||
let v_end = v_start + header.value.len();
|
let v_end = v_start + header.value.len();
|
||||||
let value = unsafe {
|
let value = unsafe {
|
||||||
|
@ -522,28 +522,34 @@ impl Reader {
|
|||||||
|
|
||||||
// convert headers
|
// convert headers
|
||||||
let msg = settings.get_http_message();
|
let msg = settings.get_http_message();
|
||||||
|
{
|
||||||
|
let msg_mut = msg.get_mut();
|
||||||
for header in headers[..headers_len].iter() {
|
for header in headers[..headers_len].iter() {
|
||||||
if let Ok(name) = HeaderName::try_from(header.name) {
|
let n_start = header.name.as_ptr() as usize - bytes_ptr;
|
||||||
|
let n_end = n_start + header.name.len();
|
||||||
|
if let Ok(name) = HeaderName::try_from(slice.slice(n_start, n_end)) {
|
||||||
let v_start = header.value.as_ptr() as usize - bytes_ptr;
|
let v_start = header.value.as_ptr() as usize - bytes_ptr;
|
||||||
let v_end = v_start + header.value.len();
|
let v_end = v_start + header.value.len();
|
||||||
let value = unsafe {
|
let value = unsafe {
|
||||||
HeaderValue::from_shared_unchecked(slice.slice(v_start, v_end)) };
|
HeaderValue::from_shared_unchecked(
|
||||||
msg.get_mut().headers.append(name, value);
|
slice.slice(v_start, v_end)) };
|
||||||
|
msg_mut.headers.append(name, value);
|
||||||
} else {
|
} else {
|
||||||
return Err(ParseError::Header)
|
return Err(ParseError::Header)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = slice.slice(path.0, path.1);
|
msg_mut.uri = Uri::from_shared(
|
||||||
let uri = Uri::from_shared(path).map_err(ParseError::Uri)?;
|
slice.slice(path.0, path.1)).map_err(ParseError::Uri)?;
|
||||||
|
msg_mut.method = method;
|
||||||
msg.get_mut().uri = uri;
|
msg_mut.version = version;
|
||||||
msg.get_mut().method = method;
|
}
|
||||||
msg.get_mut().version = version;
|
|
||||||
msg
|
msg
|
||||||
};
|
};
|
||||||
|
|
||||||
let decoder = if let Some(len) = msg.get_ref().headers.get(header::CONTENT_LENGTH) {
|
let decoder = if let Some(len) =
|
||||||
|
msg.get_ref().headers.get(header::CONTENT_LENGTH)
|
||||||
|
{
|
||||||
// Content-Length
|
// Content-Length
|
||||||
if let Ok(s) = len.to_str() {
|
if let Ok(s) = len.to_str() {
|
||||||
if let Ok(len) = s.parse::<u64>() {
|
if let Ok(len) = s.parse::<u64>() {
|
||||||
@ -570,7 +576,7 @@ impl Reader {
|
|||||||
if let Some(decoder) = decoder {
|
if let Some(decoder) = decoder {
|
||||||
let (psender, payload) = Payload::new(false);
|
let (psender, payload) = Payload::new(false);
|
||||||
let info = PayloadInfo {
|
let info = PayloadInfo {
|
||||||
tx: PayloadType::new(&msg.get_mut().headers, psender),
|
tx: PayloadType::new(&msg.get_ref().headers, psender),
|
||||||
decoder,
|
decoder,
|
||||||
};
|
};
|
||||||
msg.get_mut().payload = Some(payload);
|
msg.get_mut().payload = Some(payload);
|
||||||
|
Loading…
Reference in New Issue
Block a user