summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-08-19 14:05:47 +0200
committermetamuffin <metamuffin@disroot.org>2024-08-19 14:05:47 +0200
commitde97c34c20c3f180f2b09b0e5be8981b1e4b170f (patch)
tree5beb51e21f3f61482ccd78692d77f3d718f578e1
parent7db0a67f072d212697cda117bd65d658590e279e (diff)
downloadgnix-de97c34c20c3f180f2b09b0e5be8981b1e4b170f.tar
gnix-de97c34c20c3f180f2b09b0e5be8981b1e4b170f.tar.bz2
gnix-de97c34c20c3f180f2b09b0e5be8981b1e4b170f.tar.zst
debug module
-rw-r--r--readme.md7
-rw-r--r--src/modules/debug.rs44
-rw-r--r--src/modules/error.rs3
-rw-r--r--src/modules/files.rs7
-rw-r--r--src/modules/mod.rs2
5 files changed, 55 insertions, 8 deletions
diff --git a/readme.md b/readme.md
index 9e96f8e..5739199 100644
--- a/readme.md
+++ b/readme.md
@@ -74,7 +74,8 @@ it will automatically be loaded and applied if valid.
`/etc/letsencrypt/live` is possible. (string or list of strings)
- `cert_fallback`: Path to a single directory containing a key-cert pair that
is used when no other certificate seems appropriate. This is useful for
- testing locally with a self-signed subjectless certificate. (optional string)
+ testing locally with a self-signed subjectless certificate. (optional
+ string)
- **section `limits`**
- Note: Make sure you do not exceed the maximum file descriptor limit on your
@@ -201,6 +202,10 @@ themselves; in that case the request is passed on.
- `user`: User that the script is executed as. Requires to run gnix as root.
(optional string)
+- **module `debug`**
+ - Replies with information about the request to debug. Includes source
+ address, HTTP version, URI and headers.
+
#### Credentials config format
Login credentials for `cookie_auth` and `http_basic_auth` are supplied as either
diff --git a/src/modules/debug.rs b/src/modules/debug.rs
new file mode 100644
index 0000000..3ab03ec
--- /dev/null
+++ b/src/modules/debug.rs
@@ -0,0 +1,44 @@
+use super::{Node, NodeContext, NodeKind, NodeRequest, NodeResponse};
+use crate::error::ServiceError;
+use futures::Future;
+use http::{header::CONTENT_TYPE, HeaderValue, Response};
+use http_body_util::BodyExt;
+use serde::Deserialize;
+use serde_yaml::Value;
+use std::{pin::Pin, sync::Arc};
+
+pub struct DebugKind;
+
+#[derive(Deserialize)]
+struct Debug;
+
+impl NodeKind for DebugKind {
+ fn name(&self) -> &'static str {
+ "debug"
+ }
+ fn instanciate(&self, config: Value) -> anyhow::Result<Arc<dyn Node>> {
+ Ok(Arc::new(serde_yaml::from_value::<Debug>(config)?))
+ }
+}
+
+impl Node for Debug {
+ fn handle<'a>(
+ &'a self,
+ context: &'a mut NodeContext,
+ request: NodeRequest,
+ ) -> Pin<Box<dyn Future<Output = Result<NodeResponse, ServiceError>> + Send + Sync + 'a>> {
+ Box::pin(async move {
+ let s = format!(
+ "address: {:?}\nverion: {:?}\nuri: {:?}\nheaders: {:#?}",
+ context.addr,
+ request.version(),
+ request.uri(),
+ request.headers(),
+ );
+ let mut r = Response::new(s);
+ r.headers_mut()
+ .insert(CONTENT_TYPE, HeaderValue::from_static("text/plain"));
+ Ok(r.map(|b| b.map_err(|e| match e {}).boxed()))
+ })
+ }
+}
diff --git a/src/modules/error.rs b/src/modules/error.rs
index 504802f..01fe859 100644
--- a/src/modules/error.rs
+++ b/src/modules/error.rs
@@ -1,6 +1,5 @@
-use crate::error::ServiceError;
-
use super::{Node, NodeContext, NodeKind, NodeRequest, NodeResponse};
+use crate::error::ServiceError;
use futures::Future;
use serde::Deserialize;
use serde_yaml::Value;
diff --git a/src/modules/files.rs b/src/modules/files.rs
index 607cee1..6336648 100644
--- a/src/modules/files.rs
+++ b/src/modules/files.rs
@@ -16,7 +16,6 @@ use hyper::{
Response, StatusCode,
};
use log::debug;
-use markup::Render;
use percent_encoding::percent_decode_str;
use serde::Deserialize;
use serde_yaml::Value;
@@ -320,14 +319,12 @@ async fn index(path: &Path, rpath: String) -> Result<String, ServiceError> {
.filter(|e| e.as_ref().map(|(e, _)| !e.starts_with(".")).unwrap_or(true))
.collect::<Result<Vec<_>, _>>()?;
let banner = read_to_string(path.join("index.banner.html")).await.ok();
- let mut s = String::new();
- IndexTemplate {
+ let s = IndexTemplate {
files,
banner,
path: rpath,
}
- .render(&mut s)
- .unwrap();
+ .to_string();
Ok(s)
}
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
index dfb1f02..9840935 100644
--- a/src/modules/mod.rs
+++ b/src/modules/mod.rs
@@ -10,6 +10,7 @@ use std::{net::SocketAddr, pin::Pin, sync::Arc};
pub mod accesslog;
pub mod auth;
pub mod cgi;
+pub mod debug;
pub mod error;
pub mod file;
pub mod files;
@@ -37,6 +38,7 @@ pub static MODULES: &[&dyn NodeKind] = &[
&switch::SwitchKind,
&redirect::RedirectKind,
&cgi::CgiKind,
+ &debug::DebugKind,
];
pub struct NodeContext {