diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-10-10 14:47:54 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-10-10 14:47:54 -0600 |
commit | 04449ed66e4272ee08bc1dd00f6bdefb2be51a43 (patch) | |
tree | 665ce77a841144bd9b70becba7e541f187867406 /contrib/cgi/gemini.go | |
parent | d467d044798f61b34684e885cf5b1544c3fb2ee2 (diff) |
support an overridden "cmd" for CGIs
Diffstat (limited to 'contrib/cgi/gemini.go')
-rw-r--r-- | contrib/cgi/gemini.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/contrib/cgi/gemini.go b/contrib/cgi/gemini.go index 3ad407d..0aa3044 100644 --- a/contrib/cgi/gemini.go +++ b/contrib/cgi/gemini.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "path/filepath" "strings" sr "tildegit.org/tjp/sliderule" @@ -17,23 +18,28 @@ import ( // a request for /foo/bar/baz can also run an executable found at /foo or /foo/bar. In // such a case the PATH_INFO environment variable will include the remaining portion of // the URI path. -func GeminiCGIDirectory(fsroot, urlroot string) sr.Handler { +func GeminiCGIDirectory(fsroot, urlroot, cmd string) sr.Handler { fsroot = strings.TrimRight(fsroot, "/") return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { if !strings.HasPrefix(request.Path, urlroot) { return nil } - filepath, pathinfo, err := ResolveCGI(request.Path[len(urlroot):], fsroot) + execpath, pathinfo, err := ResolveCGI(request.Path[len(urlroot):], fsroot) if err != nil { return gemini.Failure(err) } - if filepath == "" { + if execpath == "" { return nil } + workdir := filepath.Dir(execpath) + + if cmd != "" { + execpath = cmd + } stderr := &bytes.Buffer{} - stdout, exitCode, err := RunCGI(ctx, request, filepath, pathinfo, stderr) + stdout, exitCode, err := RunCGI(ctx, request, execpath, pathinfo, workdir, stderr) if err != nil { return gemini.Failure(err) } |