Fix headers in net.serve being raw bytes instead of strings

This commit is contained in:
Filip Tibell 2024-04-18 20:54:21 +02:00
parent fe55442dac
commit 03c773fd79
No known key found for this signature in database

View file

@ -18,21 +18,30 @@ impl LuaRequest {
let path = self.head.uri.path().to_string(); let path = self.head.uri.path().to_string();
let body = lua.create_string(&self.body)?; let body = lua.create_string(&self.body)?;
let query: HashMap<String, String> = self let query: HashMap<LuaString, LuaString> = self
.head .head
.uri .uri
.query() .query()
.unwrap_or_default() .unwrap_or_default()
.split('&') .split('&')
.filter_map(|q| q.split_once('=')) .filter_map(|q| q.split_once('='))
.map(|(k, v)| (k.to_string(), v.to_string())) .map(|(k, v)| {
.collect(); let k = lua.create_string(k)?;
let headers: HashMap<String, Vec<u8>> = self let v = lua.create_string(v)?;
Ok((k, v))
})
.collect::<LuaResult<_>>()?;
let headers: HashMap<LuaString, LuaString> = self
.head .head
.headers .headers
.iter() .iter()
.map(|(k, v)| (k.as_str().to_string(), v.as_bytes().to_vec())) .map(|(k, v)| {
.collect(); let k = lua.create_string(k.as_str())?;
let v = lua.create_string(v.as_bytes())?;
Ok((k, v))
})
.collect::<LuaResult<_>>()?;
TableBuilder::new(lua)? TableBuilder::new(lua)?
.with_value("method", method)? .with_value("method", method)?