summaryrefslogtreecommitdiff
path: root/src/handlers/mod.rs
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2026-03-01 17:34:34 -0500
committerJohn Turner <jturner.usa@gmail.com>2026-03-01 17:34:34 -0500
commit3c4208abd325d317c7524ba0dc3b701edfa9ebf8 (patch)
tree197a3d46fcad3ed8d7f3b3d0d0c0fc3f79e3a204 /src/handlers/mod.rs
parent06476ea44ff27bd9b4af2aa5bcf715fe9034db9a (diff)
downloadhttpd-master.tar.gz
impl basic static file serverHEADmaster
Diffstat (limited to 'src/handlers/mod.rs')
-rw-r--r--src/handlers/mod.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs
new file mode 100644
index 0000000..800b61e
--- /dev/null
+++ b/src/handlers/mod.rs
@@ -0,0 +1,38 @@
+use mlua::{FromLua, Value};
+
+use crate::{handlers::staticfile::StaticFile, request::Request, response::Response};
+
+mod staticfile;
+
+pub(super) trait Handle<T> {
+ async fn handle(&self, request: Request<T>) -> 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, Clone)]
+pub enum Handlers {
+ StaticFile(StaticFile),
+}
+
+impl FromLua for Handlers {
+ 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")),
+ }
+ }
+}