mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Unbreak accidental breaking change in net.serve
This commit is contained in:
parent
0116d405b2
commit
59aa780654
2 changed files with 31 additions and 31 deletions
|
@ -4,43 +4,42 @@ use http::request::Parts;
|
|||
|
||||
use mlua::prelude::*;
|
||||
|
||||
use crate::lune::util::TableBuilder;
|
||||
|
||||
pub(super) struct LuaRequest {
|
||||
pub(super) _remote_addr: SocketAddr,
|
||||
pub(super) head: Parts,
|
||||
pub(super) body: Vec<u8>,
|
||||
}
|
||||
|
||||
impl LuaUserData for LuaRequest {
|
||||
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
||||
fields.add_field_method_get("method", |_, this| {
|
||||
Ok(this.head.method.as_str().to_string())
|
||||
});
|
||||
impl LuaRequest {
|
||||
pub fn into_lua_table(self, lua: &Lua) -> LuaResult<LuaTable> {
|
||||
let method = self.head.method.as_str().to_string();
|
||||
let path = self.head.uri.path().to_string();
|
||||
let body = lua.create_string(&self.body)?;
|
||||
|
||||
fields.add_field_method_get("path", |_, this| Ok(this.head.uri.path().to_string()));
|
||||
let query: HashMap<String, String> = 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<String, Vec<u8>> = self
|
||||
.head
|
||||
.headers
|
||||
.iter()
|
||||
.map(|(k, v)| (k.as_str().to_string(), v.as_bytes().to_vec()))
|
||||
.collect();
|
||||
|
||||
fields.add_field_method_get("query", |_, this| {
|
||||
let query: HashMap<String, String> = this
|
||||
.head
|
||||
.uri
|
||||
.query()
|
||||
.unwrap_or_default()
|
||||
.split('&')
|
||||
.filter_map(|q| q.split_once('='))
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect();
|
||||
Ok(query)
|
||||
});
|
||||
|
||||
fields.add_field_method_get("headers", |_, this| {
|
||||
let headers: HashMap<String, Vec<u8>> = this
|
||||
.head
|
||||
.headers
|
||||
.iter()
|
||||
.map(|(k, v)| (k.as_str().to_string(), v.as_bytes().to_vec()))
|
||||
.collect();
|
||||
Ok(headers)
|
||||
});
|
||||
|
||||
fields.add_field_method_get("body", |lua, this| lua.create_string(&this.body));
|
||||
TableBuilder::new(lua)?
|
||||
.with_value("method", method)?
|
||||
.with_value("path", path)?
|
||||
.with_value("query", query)?
|
||||
.with_value("headers", headers)?
|
||||
.with_value("body", body)?
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,9 @@ impl Service<Request<Incoming>> for Svc {
|
|||
head,
|
||||
body,
|
||||
};
|
||||
let lua_req_table = lua_req.into_lua_table(&lua)?;
|
||||
|
||||
let thread_id = lua.push_thread_back(handler_request, lua_req)?;
|
||||
let thread_id = lua.push_thread_back(handler_request, lua_req_table)?;
|
||||
lua.track_thread(thread_id);
|
||||
lua.wait_for_thread(thread_id).await;
|
||||
let thread_res = lua
|
||||
|
|
Loading…
Reference in a new issue