diff --git a/src/lune/builtins/net/server/request.rs b/src/lune/builtins/net/server/request.rs index dde529f..bab7a5d 100644 --- a/src/lune/builtins/net/server/request.rs +++ b/src/lune/builtins/net/server/request.rs @@ -18,21 +18,30 @@ impl LuaRequest { let path = self.head.uri.path().to_string(); let body = lua.create_string(&self.body)?; - let query: HashMap = self + let query: HashMap = self .head .uri .query() .unwrap_or_default() .split('&') .filter_map(|q| q.split_once('=')) - .map(|(k, v)| (k.to_string(), v.to_string())) - .collect(); - let headers: HashMap> = self + .map(|(k, v)| { + let k = lua.create_string(k)?; + let v = lua.create_string(v)?; + Ok((k, v)) + }) + .collect::>()?; + + let headers: HashMap = self .head .headers .iter() - .map(|(k, v)| (k.as_str().to_string(), v.as_bytes().to_vec())) - .collect(); + .map(|(k, v)| { + let k = lua.create_string(k.as_str())?; + let v = lua.create_string(v.as_bytes())?; + Ok((k, v)) + }) + .collect::>()?; TableBuilder::new(lua)? .with_value("method", method)?