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()?;
if buffer.len() > 0 {
fcgi_send_stdout(self, self.id, Some(buffer.to_vec()))?; fcgi_send_stdout(self, self.id, Some(buffer.to_vec()))?;
}
buffer.len() buffer.len()
}; };
if length == 0 { if length == 0 {
@ -1532,7 +1534,10 @@ 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 pos = 0;
while pos < vec.len() {
let data = &vec[pos..];
let mut index: usize = 1; let mut index: usize = 1;
let key_len = fcgi_decode_strlen(data); let key_len = fcgi_decode_strlen(data);
if key_len > 127 { if key_len > 127 {
@ -1545,16 +1550,19 @@ fn fcgi_decode_params(rq: &mut FGCIRequest, data: &Vec<u8>) -> Result<(), std::i
} else { } else {
index += 1; index += 1;
} }
//INFO!("data: {:?}", data); //DEBUG!("data: {:?}", data);
//INFO!("key: {:?}", data[index..index + key_len].to_vec()); //DEBUG!("key: {:?}", data[index..index + key_len].to_vec());
//INFO!("Value: {:?}", data[index+key_len..index+key_len+value_len].to_vec()); //DEBUG!("Value: {:?}", data[index+key_len..index+key_len+value_len].to_vec());
let key = String::from_utf8(data[index..index + key_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()))?;
let value: String = let value: String =
String::from_utf8(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())
.map_err(|e| ERR!(e.to_string()))?; .map_err(|e| ERR!(e.to_string()))?;
DEBUG!("PARAM: [{}] -> [{}]", key, value); DEBUG!("PARAM: [{}] -> [{}]", key, value);
pos = pos + index + key_len + value_len;
let _ = rq.params.insert(key, value); let _ = rq.params.insert(key, value);
}
Ok(()) Ok(())
} }