mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
http protocol: return NeedMoreData until headers are fully parsed
This prevents an issue in aquatic_http where it could theoretically start sending back data before initial request was fully received.
This commit is contained in:
parent
fcf18c845f
commit
1b5fbe8775
1 changed files with 6 additions and 14 deletions
|
|
@ -262,25 +262,17 @@ impl Request {
|
||||||
let mut headers = [httparse::EMPTY_HEADER; 16];
|
let mut headers = [httparse::EMPTY_HEADER; 16];
|
||||||
let mut http_request = httparse::Request::new(&mut headers);
|
let mut http_request = httparse::Request::new(&mut headers);
|
||||||
|
|
||||||
let path = match http_request.parse(bytes) {
|
match http_request.parse(bytes) {
|
||||||
Ok(httparse::Status::Complete(_)) => {
|
Ok(httparse::Status::Complete(_)) => {
|
||||||
if let Some(path) = http_request.path {
|
if let Some(path) = http_request.path {
|
||||||
path
|
Self::from_http_get_path(path).map_err(RequestParseError::Invalid)
|
||||||
} else {
|
} else {
|
||||||
return Err(RequestParseError::Invalid(anyhow::anyhow!("no http path")));
|
Err(RequestParseError::Invalid(anyhow::anyhow!("no http path")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(httparse::Status::Partial) => {
|
Ok(httparse::Status::Partial) => Err(RequestParseError::NeedMoreData),
|
||||||
if let Some(path) = http_request.path {
|
Err(err) => Err(RequestParseError::Invalid(anyhow::Error::from(err))),
|
||||||
path
|
}
|
||||||
} else {
|
|
||||||
return Err(RequestParseError::NeedMoreData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => return Err(RequestParseError::Invalid(anyhow::Error::from(err))),
|
|
||||||
};
|
|
||||||
|
|
||||||
Self::from_http_get_path(path).map_err(RequestParseError::Invalid)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse Request from http path (GET `/announce?info_hash=...`)
|
/// Parse Request from http path (GET `/announce?info_hash=...`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue