From 26aac34fdf0b76f33b11e00cb2ec4c5f2b757af1 Mon Sep 17 00:00:00 2001 From: gennyble Date: Sun, 16 Mar 2025 04:44:05 -0500 Subject: debugging --- Cargo.lock | 7 +++ Cargo.toml | 11 ++-- README.md | 10 ++++ corgi.conf | 16 +++++- src/main.rs | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 184 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7f322a..a379ab8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,6 +57,7 @@ dependencies = [ "http-body-util", "hyper", "hyper-util", + "regex-lite", "tokio", ] @@ -244,6 +245,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + [[package]] name = "rustc-demangle" version = "0.1.24" diff --git a/Cargo.toml b/Cargo.toml index f53fcbc..fa58787 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2024" [profile.release] -strip = true -opt-level = "z" -lto = true -codegen-units = 1 +#strip = true +#opt-level = "z" +#lto = true +#codegen-units = 1 # 1538792 none of the above flags # 829896 the above flags reduced binary size by around 700K :) @@ -15,6 +15,7 @@ codegen-units = 1 [dependencies] http-body-util = "0.1.3" hyper-util = { version = "0.1.10", features = ["tokio"] } +regex-lite = "0.1.6" [dependencies.confindent] version = "2.2.1" @@ -23,7 +24,7 @@ branch = "v2" [dependencies.tokio] version = "1.44.0" -features = ["rt", "rt-multi-thread", "io-std", "net", "process"] +features = ["rt", "rt-multi-thread", "io-std", "io-util", "net", "process"] [dependencies.hyper] version = "1.6.0" diff --git a/README.md b/README.md index ef2dd2b..47b3449 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,22 @@ corgi listens on port 26744 by default. `/etc/corgi.conf` ``` +Server + Port 26744 + +Script + Match + Regex + Script Environment HTTP_HOST ENV_KEY ``` +Scripts are tried in order, looking for one that matches. If none match, +the first script is ran. + Sets the following environmental variables for the CGI script, many following [RFC 3875][rfc]: - **`GATEWAY_INTERFACE`** to the fixed value `CGI/1.1` - **`PATH_INFO`** to the HTTP path the client requested diff --git a/corgi.conf b/corgi.conf index fb3e7ad..207acc7 100644 --- a/corgi.conf +++ b/corgi.conf @@ -1,3 +1,17 @@ -Script /usr/lib/cgit/cgit.cgi +Server + Port 26744 + +Script git-backend + Path /usr/lib/git-core/git-http-backend + Match + Regex /.+/(info/refs|git-upload-pack) + Environment + GIT_HTTP_EXPORT_ALL 1 + GIT_PROJECT_ROOT /srv/git + HOME /srv/git + HTTP_HOST git.nyble.dev + +Script cgit + Path /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 0493fdb..9831331 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,25 +1,39 @@ use std::{ net::{IpAddr, SocketAddr}, pin::Pin, + process::Stdio, time::Instant, }; -use confindent::{Confindent, ValueParseError}; +use confindent::{Confindent, Value, ValueParseError}; use http_body_util::{BodyExt, Full}; use hyper::{ HeaderMap, Request, Response, StatusCode, body::{Bytes, Incoming}, - header::HeaderValue, + header::{self, HeaderValue}, server::conn::http1, service::Service, }; use hyper_util::rt::TokioIo; -use tokio::{net::TcpListener, process::Command, runtime::Runtime}; +use regex_lite::Regex; +use tokio::{ + io::{AsyncWriteExt, BufWriter}, + net::TcpListener, + process::Command, + runtime::Runtime, +}; #[derive(Clone, Debug)] pub struct Settings { port: u16, - script_filename: String, + scripts: Vec