From 03c773fd7928a8afa39c0515e97a5cdc0436d95b Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Thu, 18 Apr 2024 20:54:21 +0200 Subject: [PATCH] Fix headers in net.serve being raw bytes instead of strings --- src/lune/builtins/net/server/request.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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)?