1
0
Fork 0

Expand CGI path globs once on startup, not for each request.

This commit is contained in:
Solderpunk 2020-07-01 16:18:49 +02:00
parent 35bf4d16c3
commit f4f14320df
2 changed files with 12 additions and 9 deletions

View file

@ -2,6 +2,7 @@ package main
import ( import (
"errors" "errors"
"path/filepath"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
) )
@ -79,5 +80,16 @@ func getConfig(filename string) (Config, error) {
return config, errors.New("Invalid DirectorySort value.") return config, errors.New("Invalid DirectorySort value.")
} }
// Expand CGI paths
var cgiPaths []string
for _, cgiPath := range config.CGIPaths {
expandedPaths, err := filepath.Glob(cgiPath)
if err != nil {
return config, errors.New("Error expanding CGI path glob " + cgiPath + ": " + err.Error())
}
cgiPaths = append(cgiPaths, expandedPaths...)
}
config.CGIPaths = cgiPaths
return config, nil return config, nil
} }

View file

@ -100,16 +100,7 @@ func handleGeminiRequest(conn net.Conn, config Config, accessLogEntries chan Log
} }
// Check whether this URL is in a configured CGI path // Check whether this URL is in a configured CGI path
var cgiPaths []string
for _, cgiPath := range config.CGIPaths { for _, cgiPath := range config.CGIPaths {
expandedPaths, err := filepath.Glob(cgiPath)
if err != nil {
errorLogEntries <- "Error expanding CGI path glob " + cgiPath + ": " + err.Error()
continue
}
cgiPaths = append(cgiPaths, expandedPaths...)
}
for _, cgiPath := range cgiPaths {
if strings.HasPrefix(path, cgiPath) { if strings.HasPrefix(path, cgiPath) {
handleCGI(config, path, cgiPath, URL, &log, errorLogEntries, conn) handleCGI(config, path, cgiPath, URL, &log, errorLogEntries, conn)
if log.Status != 0 { if log.Status != 0 {