about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2025-03-11 16:59:28 -0500
committergennyble <gen@nyble.dev>2025-03-11 16:59:28 -0500
commitb0ebb00d5301e8ac2b1a2ea6504c711ced1ee7f4 (patch)
treeae7975051973413b1ae9756fcf41cde11d4173cb
parente63dc83b56772a40b9ffb1e509bbc1da55f0b6f9 (diff)
downloadcorgi-b0ebb00d5301e8ac2b1a2ea6504c711ced1ee7f4.tar.gz
corgi-b0ebb00d5301e8ac2b1a2ea6504c711ced1ee7f4.zip
env vars from conf
-rw-r--r--Cargo.lock5
-rw-r--r--Cargo.toml6
-rw-r--r--README.md3
-rw-r--r--corgi.conf4
-rw-r--r--src/main.rs14
5 files changed, 26 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 25241c8..f7f322a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -46,9 +46,8 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
 [[package]]
 name = "confindent"
-version = "2.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c5a06ecfd8e0b653f5b0a1b083f74a275d2aab7834b90bce8c66f3c0b2f53fb1"
+version = "2.2.1"
+source = "git+https://github.com/gennyble/confindent?branch=v2#127f579c284131feb15f5deec45dde57a5f44284"
 
 [[package]]
 name = "corgi"
diff --git a/Cargo.toml b/Cargo.toml
index 77232e3..a634a91 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,10 +4,14 @@ version = "0.1.0"
 edition = "2024"
 
 [dependencies]
-confindent = "2.2.0"
 http-body-util = "0.1.3"
 hyper-util = { version = "0.1.10", features = ["tokio"] }
 
+[dependencies.confindent]
+version = "2.2.1"
+git = "https://github.com/gennyble/confindent"
+branch = "v2"
+
 [dependencies.tokio]
 version = "1.44.0"
 features = ["rt", "rt-multi-thread", "io-std", "net", "process"]
diff --git a/README.md b/README.md
index aa164df..09b2e8c 100644
--- a/README.md
+++ b/README.md
@@ -5,4 +5,7 @@ currently, it can handle one application.
 `/etc/corgi.conf`
 ```
 Script <path-to-cgi-script>
+	Environment
+		HTTP_HOST <hostname>
+		ENV_KEY <some-env-value>
 ```
\ No newline at end of file
diff --git a/corgi.conf b/corgi.conf
index 065d9ea..fb3e7ad 100644
--- a/corgi.conf
+++ b/corgi.conf
@@ -1 +1,3 @@
-Script /usr/lib/cgit/cgit.cgi
\ No newline at end of file
+Script /usr/lib/cgit/cgit.cgi
+	Environment
+		HTTP_HOST git.nyble.dev
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index e0f20a1..27d3820 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,9 +25,13 @@ fn main() {
 	let conf = Confindent::from_file(conf_path).expect("failed to open conf");
 
 	let script = conf.child("Script").expect("no 'Script' key in conf");
+	let environment = script.child("Environment");
+	let env = environment
+		.map(|e| e.values().map(|v| (v.key_owned(), v.value_owned().unwrap())).collect());
+
 	let settings = Settings {
 		script_filename: script.value_owned().expect("'Script' key has no value'"),
-		env: vec![],
+		env: env.unwrap_or_default(),
 	};
 
 	let rt = Runtime::new().unwrap();
@@ -92,9 +96,17 @@ impl Svc {
 				if hname.to_ascii_lowercase() == "user-agent" {
 					println!("USER_AGENT: {hvalue}");
 				}
+
+				if hname.to_ascii_lowercase() == "host" {
+					println!("HOST: {hvalue}");
+				}
 			}
 		}
 
+		for (key, value) in &settings.env {
+			cmd.env(key.to_ascii_uppercase(), value);
+		}
+
 		/*if content_length > 0 {
 			cmd.env("CONTENT_LENGTH", content_length.to_string());
 		}*/