summaryrefslogtreecommitdiff
path: root/contrib/cgi/spartan.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-09-30 20:08:33 -0600
committertjpcc <tjp@ctrl-c.club>2023-09-30 20:08:53 -0600
commit775c0c1040e6a6622fec39d49b354bfa194a6998 (patch)
treef46edde7ee0392ae714f4facfd4e64244814c040 /contrib/cgi/spartan.go
parent09c482d5016cfc7b628058893a1644fdf5fa699f (diff)
file serving refactor
* do away with fs.FS usage in gemini, like the previous refactor in gopher * remove spartan code in contrib * standardize fsroot/urlroot string arguments to file serving handlers
Diffstat (limited to 'contrib/cgi/spartan.go')
-rw-r--r--contrib/cgi/spartan.go54
1 files changed, 0 insertions, 54 deletions
diff --git a/contrib/cgi/spartan.go b/contrib/cgi/spartan.go
deleted file mode 100644
index 272bd92..0000000
--- a/contrib/cgi/spartan.go
+++ /dev/null
@@ -1,54 +0,0 @@
-package cgi
-
-import (
- "bytes"
- "context"
- "fmt"
- "strings"
-
- sr "tildegit.org/tjp/sliderule"
- "tildegit.org/tjp/sliderule/logging"
- "tildegit.org/tjp/sliderule/spartan"
-)
-
-// SpartanCGIDirectory runs executable files relative to a root directory in the file system.
-//
-// It will also find any run any executable _part way_ through the path, so for example 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.
-func SpartanCGIDirectory(pathRoot, fsRoot string) sr.Handler {
- fsRoot = strings.TrimRight(fsRoot, "/")
- return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
- if !strings.HasPrefix(request.Path, pathRoot) {
- return nil
- }
-
- filepath, pathinfo, err := ResolveCGI(request.Path[len(pathRoot):], fsRoot)
- if err != nil {
- return spartan.ServerError(err)
- }
- if filepath == "" {
- return nil
- }
-
- stderr := &bytes.Buffer{}
- stdout, exitCode, err := RunCGI(ctx, request, filepath, pathinfo, stderr)
- if err != nil {
- return spartan.ServerError(err)
- }
- if exitCode != 0 {
- ctx.Value("warnlog").(logging.Logger).Log(
- "msg", "cgi exited with non-zero exit code",
- "code", exitCode,
- "stderr", stderr.String(),
- )
- return spartan.ServerError(fmt.Errorf("CGI process exited with status %d", exitCode))
- }
-
- response, err := spartan.ParseResponse(stdout)
- if err != nil {
- return spartan.ServerError(err)
- }
- return response
- })
-}