fix: improve protocol implementations to comply with the FastCGI specification
All checks were successful
gitea-sync/luafcgi/pipeline/head This commit looks good

This commit is contained in:
DanyLE 2023-09-15 13:33:40 +02:00
parent 3153cc48af
commit 77cfca2fac

View File

@ -728,7 +728,9 @@ impl FCGIOStream {
loop { loop {
let length = { let length = {
let buffer = buf_reader.fill_buf()?; let buffer = buf_reader.fill_buf()?;
fcgi_send_stdout(self, self.id, Some(buffer.to_vec()))?; if buffer.len() > 0 {
fcgi_send_stdout(self, self.id, Some(buffer.to_vec()))?;
}
buffer.len() buffer.len()
}; };
if length == 0 { if length == 0 {
@ -1532,29 +1534,35 @@ fn fcgi_decode_strlen(data: &[u8]) -> usize {
} }
} }
fn fcgi_decode_params(rq: &mut FGCIRequest, data: &Vec<u8>) -> Result<(), std::io::Error> { fn fcgi_decode_params(rq: &mut FGCIRequest, vec: &Vec<u8>) -> Result<(), std::io::Error> {
let mut index: usize = 1; let mut pos = 0;
let key_len = fcgi_decode_strlen(data); while pos < vec.len() {
if key_len > 127 { let data = &vec[pos..];
index = 4; let mut index: usize = 1;
} let key_len = fcgi_decode_strlen(data);
let value_len = fcgi_decode_strlen(&data[index..]); if key_len > 127 {
//INFO!("Key len {}, value len {}", key_len, value_len); index = 4;
if value_len > 127 { }
index += 4; let value_len = fcgi_decode_strlen(&data[index..]);
} else { //INFO!("Key len {}, value len {}", key_len, value_len);
index += 1; if value_len > 127 {
} index += 4;
//INFO!("data: {:?}", data); } else {
//INFO!("key: {:?}", data[index..index + key_len].to_vec()); index += 1;
//INFO!("Value: {:?}", data[index+key_len..index+key_len+value_len].to_vec()); }
let key = String::from_utf8(data[index..index + key_len].to_vec()) //DEBUG!("data: {:?}", data);
.map_err(|e| ERR!(e.to_string()))?; //DEBUG!("key: {:?}", data[index..index + key_len].to_vec());
let value: String = //DEBUG!("Value: {:?}", data[index+key_len..index+key_len+value_len].to_vec());
String::from_utf8(data[index + key_len..index + key_len + value_len].to_vec()) let key = String::from_utf8(data[index..index + key_len].to_vec())
.map_err(|e| ERR!(e.to_string()))?; .map_err(|e| ERR!(e.to_string()))?;
DEBUG!("PARAM: [{}] -> [{}]", key, value); let value: String =
let _ = rq.params.insert(key, value); String::from_utf8(data[index + key_len..index + key_len + value_len].to_vec())
.map_err(|e| ERR!(e.to_string()))?;
DEBUG!("PARAM: [{}] -> [{}]", key, value);
pos = pos + index + key_len + value_len;
let _ = rq.params.insert(key, value);
}
Ok(()) Ok(())
} }