summaryrefslogtreecommitdiff
path: root/contrib/cgi/cgi.go
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/cgi/cgi.go')
-rw-r--r--contrib/cgi/cgi.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/contrib/cgi/cgi.go b/contrib/cgi/cgi.go
index bcdd5e1..749a284 100644
--- a/contrib/cgi/cgi.go
+++ b/contrib/cgi/cgi.go
@@ -25,11 +25,11 @@ import (
// a request for /foo/bar/baz can run an executable found at /foo or /foo/bar. In such
// a case the PATH_INFO would include the remaining portion of the URI path.
func ResolveCGI(requestPath, fsRoot string) (string, string, error) {
+ fsRoot = strings.TrimRight(fsRoot, "/")
segments := strings.Split(strings.TrimLeft(requestPath, "/"), "/")
for i := range append(segments, "") {
filepath := strings.Join(append([]string{fsRoot}, segments[:i]...), "/")
- filepath = strings.TrimRight(filepath, "/")
isDir, isExecutable, err := executableFile(filepath)
if err != nil {
return "", "", err
@@ -52,26 +52,20 @@ func ResolveCGI(requestPath, fsRoot string) (string, string, error) {
}
func executableFile(filepath string) (bool, bool, error) {
- file, err := os.Open(filepath)
+ info, err := os.Stat(filepath)
if isNotExistError(err) {
return false, false, nil
}
if err != nil {
return false, false, err
}
- defer file.Close()
-
- info, err := file.Stat()
- if err != nil {
- return false, false, err
- }
if info.IsDir() {
return true, false, nil
}
// readable + executable by anyone
- return false, info.Mode()&0005 == 0005, nil
+ return false, info.Mode()&5 == 5, nil
}
func isNotExistError(err error) bool {
@@ -94,7 +88,7 @@ func RunCGI(
request *sr.Request,
executable string,
pathInfo string,
-) (io.Reader, int, error) {
+) (*bytes.Buffer, int, error) {
pathSegments := strings.Split(executable, "/")
dirPath := "."
@@ -105,7 +99,7 @@ func RunCGI(
infoLen := len(pathInfo)
if pathInfo == "/" {
- infoLen -= 1
+ infoLen = 0
}
scriptName := request.Path[:len(request.Path)-infoLen]