From e71226e93702268295d989c5ac7a103a1553a13a Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 11 May 2022 14:26:14 +0000 Subject: [PATCH 1/2] Add -r flag to set CGI SCRIPT_NAME --- main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 2019888..6366db0 100644 --- a/main.go +++ b/main.go @@ -24,9 +24,11 @@ func main() { // The default usage message isn't very helpful, so we provide our own. flag.Usage = func() { - fmt.Fprintln(flag.CommandLine.Output(), "Usage: cgiserver /path/to/application.cgi") + fmt.Fprintln(flag.CommandLine.Output(), "Usage: cgiserver [-r ROOT] /path/to/application.cgi") } + root := flag.String("r", "/", "CGI SCRIPT_NAME"); + // We didn't configure any flags, so this just serves to display an error // if someone tries to pass one. It also automatically handles -h/--help. flag.Parse() @@ -53,6 +55,7 @@ func main() { // ...and Go's standard library does literally all of the hard work. handler = &cgi.Handler{ Path: path, + Root: *root, Env: os.Environ(), // Environment variables aren't inherited by default. } -- 2.35.1