diff options
| author | John Turner <jturner.usa@gmail.com> | 2026-03-04 20:53:24 -0500 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2026-03-04 20:53:32 -0500 |
| commit | 4a16841789604614bc495c36972236749e5f35b0 (patch) | |
| tree | ff7383c17f5d265967a1db083884fec78062e53f /src/handler.rs | |
| parent | 3c4208abd325d317c7524ba0dc3b701edfa9ebf8 (diff) | |
| download | httpd-4a16841789604614bc495c36972236749e5f35b0.tar.gz | |
roll our own http types
Diffstat (limited to 'src/handler.rs')
| -rw-r--r-- | src/handler.rs | 38 |
1 files changed, 38 insertions, 0 deletions
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<Output = Result<Response, Error>>; +} + +#[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<Self> { + match value { + Value::Table(table) => match table.get::<String>("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")), + } + } +} |
