From 4a16841789604614bc495c36972236749e5f35b0 Mon Sep 17 00:00:00 2001 From: John Turner Date: Wed, 4 Mar 2026 20:53:24 -0500 Subject: roll our own http types --- src/handler.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/handler.rs (limited to 'src/handler.rs') diff --git a/src/handler.rs b/src/handler.rs new file mode 100644 index 0000000..45dc879 --- /dev/null +++ b/src/handler.rs @@ -0,0 +1,38 @@ +mod staticfile; + +use mlua::{FromLua, Value}; + +use crate::{handler::staticfile::StaticFile, request::Request, response::Response}; + +pub trait Handle { + fn handle(self, request: Request) -> impl Future>; +} + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("unsupported method")] + Unsupported, + + #[error("static file handler error: {0}")] + StaticFile(#[from] staticfile::Error), +} + +#[derive(Debug)] +pub enum Handler { + StaticFile(StaticFile), +} + +impl FromLua for Handler { + fn from_lua(value: Value, lua: &mlua::Lua) -> mlua::Result { + match value { + Value::Table(table) => match table.get::("handler")?.as_str() { + "staticfile" => Ok(Self::StaticFile(StaticFile::from_lua( + Value::Table(table.clone()), + lua, + )?)), + _ => Err(mlua::Error::runtime("unknown handler")), + }, + _ => Err(mlua::Error::runtime("expected table")), + } + } +} -- cgit v1.2.3