mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_http: prococol module: parse Request from path
This commit is contained in:
parent
d5b82bcf70
commit
fb6caf7343
2 changed files with 13 additions and 15 deletions
|
|
@ -65,19 +65,21 @@ impl EstablishedConnection {
|
|||
}
|
||||
|
||||
let mut headers = [httparse::EMPTY_HEADER; 16];
|
||||
let mut request = httparse::Request::new(&mut headers);
|
||||
let mut http_request = httparse::Request::new(&mut headers);
|
||||
|
||||
let request = match request.parse(&self.buf[..self.bytes_read]){
|
||||
match http_request.parse(&self.buf[..self.bytes_read]){
|
||||
Ok(httparse::Status::Complete(_)) => {
|
||||
let result = if let Some(request) = Request::from_http(request){
|
||||
Ok(request)
|
||||
} else {
|
||||
Err(RequestReadError::Invalid)
|
||||
};
|
||||
let opt_request = http_request.path.and_then(
|
||||
Request::from_http_get_path
|
||||
);
|
||||
|
||||
self.bytes_read = 0;
|
||||
|
||||
result
|
||||
if let Some(request) = opt_request {
|
||||
Ok(request)
|
||||
} else {
|
||||
Err(RequestReadError::Invalid)
|
||||
}
|
||||
},
|
||||
Ok(httparse::Status::Partial) => {
|
||||
Err(RequestReadError::NeedMoreData)
|
||||
|
|
@ -87,9 +89,7 @@ impl EstablishedConnection {
|
|||
|
||||
Err(RequestReadError::Parse(err))
|
||||
}
|
||||
};
|
||||
|
||||
request
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_response(&mut self, body: &[u8]) -> ::std::io::Result<()> {
|
||||
|
|
|
|||
|
|
@ -142,10 +142,8 @@ pub enum Request {
|
|||
|
||||
|
||||
impl Request {
|
||||
pub fn from_http(http: httparse::Request) -> Option<Self> {
|
||||
log::debug!("path: {:?}", http.path);
|
||||
|
||||
let path = http.path?;
|
||||
pub fn from_http_get_path(path: &str) -> Option<Self> {
|
||||
log::debug!("path: {:?}", path);
|
||||
|
||||
let mut split_parts= path.splitn(2, '?');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue