mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +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 http_request = httparse::Request::new(&mut headers);
|
||||
|
||||
let path = match http_request.parse(bytes) {
|
||||
match http_request.parse(bytes) {
|
||||
Ok(httparse::Status::Complete(_)) => {
|
||||
if let Some(path) = http_request.path {
|
||||
path
|
||||
Self::from_http_get_path(path).map_err(RequestParseError::Invalid)
|
||||
} else {
|
||||
return Err(RequestParseError::Invalid(anyhow::anyhow!("no http path")));
|
||||
Err(RequestParseError::Invalid(anyhow::anyhow!("no http path")))
|
||||
}
|
||||
}
|
||||
Ok(httparse::Status::Partial) => {
|
||||
if let Some(path) = http_request.path {
|
||||
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)
|
||||
Ok(httparse::Status::Partial) => Err(RequestParseError::NeedMoreData),
|
||||
Err(err) => Err(RequestParseError::Invalid(anyhow::Error::from(err))),
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse Request from http path (GET `/announce?info_hash=...`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue