From 1d9fa34fa84cc125c68ab486d8bbc2dbe7a51f0e Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sun, 27 Apr 2025 14:02:53 -0400 Subject: feat(httpdebug): quiet mode and function as a systemd service Signed-off-by: Xe Iaso --- cmd/httpdebug/httpdebug.env | 0 cmd/httpdebug/httpdebug.service | 13 +++++++++++++ cmd/httpdebug/main.go | 11 ++++++++--- yeetfile.js | 26 ++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 cmd/httpdebug/httpdebug.env create mode 100644 cmd/httpdebug/httpdebug.service diff --git a/cmd/httpdebug/httpdebug.env b/cmd/httpdebug/httpdebug.env new file mode 100644 index 0000000..e69de29 diff --git a/cmd/httpdebug/httpdebug.service b/cmd/httpdebug/httpdebug.service new file mode 100644 index 0000000..01cf9af --- /dev/null +++ b/cmd/httpdebug/httpdebug.service @@ -0,0 +1,13 @@ +[Unit] +Description="http debugger" + +[Service] +ExecStart=/usr/bin/httpdebug +Restart=always +RestartSec=30s +EnvironmentFile=/etc/within.website/x/httpdebug.env +LimitNOFILE=infinity +DynamicUser=true + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/cmd/httpdebug/main.go b/cmd/httpdebug/main.go index 8162bc2..15943b7 100644 --- a/cmd/httpdebug/main.go +++ b/cmd/httpdebug/main.go @@ -14,7 +14,8 @@ import ( ) var ( - bind = flag.String("bind", ":3000", "TCP port to bind to") + bind = flag.String("bind", ":3000", "TCP port to bind to") + silent = flag.Bool("silent", false, "if set, don't log http headers") ) func main() { @@ -34,8 +35,12 @@ func main() { fmt.Fprint(w, "
")
 		}
 
-		fmt.Println("---")
-		r.Write(io.MultiWriter(w, os.Stdout))
+		if !*silent {
+			fmt.Println("---")
+			r.Header.Write(io.MultiWriter(w, os.Stdout))
+		} else {
+			r.Header.Write(w)
+		}
 
 		if contains {
 			fmt.Fprintln(w, "
") diff --git a/yeetfile.js b/yeetfile.js index 946e764..87fa4c7 100644 --- a/yeetfile.js +++ b/yeetfile.js @@ -26,6 +26,32 @@ const pkgs = []; ["amd64", "arm64"].forEach((goarch) => { [deb, rpm].forEach((method) => { + pkgs.push( + method.build({ + name: "httpdebug", + description: "HTTP protocol debugger", + homepage: "https://within.website", + license: "CC0", + goarch, + + documentation: { + LICENSE: "LICENSE", + }, + + configFiles: { + "cmd/httpdebug/httpdebug.env": "/etc/within.website/x/httpdebug.env", + }, + + build: ({ bin, systemd }) => { + $`go build -o ${bin}/httpdebug -ldflags '-s -w -extldflags "-static" -X "within.website/x.Version=${git.tag()}"' ./cmd/httpdebug`; + file.install( + "./cmd/httpdebug/httpdebug.service", + `${systemd}/httpdebug.service`, + ); + }, + }), + ); + pkgs.push( method.build({ name: "ingressd", -- cgit v1.2.3