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,22 +4,21 @@ 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()));
|
||||
|
||||
fields.add_field_method_get("query", |_, this| {
|
||||
let query: HashMap<String, String> = this
|
||||
let query: HashMap<String, String> = self
|
||||
.head
|
||||
.uri
|
||||
.query()
|
||||
|
@ -28,19 +27,19 @@ impl LuaUserData for LuaRequest {
|
|||
.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
|
||||
let headers: HashMap<String, Vec<u8>> = self
|
||||
.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