move shlex parsing to server startup time

This commit is contained in:
Travis J Parker 2022-06-14 18:39:10 +02:00
parent c9838f3f29
commit 50f9d49e6c
2 changed files with 14 additions and 8 deletions

View File

@ -6,6 +6,8 @@ import (
"log"
"os"
"path/filepath"
"github.com/google/shlex"
)
type Config struct {
@ -30,6 +32,8 @@ type Config struct {
DirectorySort string
DirectoryReverse bool
DirectoryTitles bool
cgiCommandArgs []string
}
type MollyFile struct {
@ -95,6 +99,15 @@ func getConfig(filename string) (Config, error) {
}
config.CGIPaths = cgiPaths
if config.CGICommand != "" {
spl, err := shlex.Split(config.CGICommand)
if err != nil {
return config, err
}
config.CGICommand = spl[0]
config.cgiCommandArgs = spl[1:]
}
return config, nil
}

View File

@ -13,8 +13,6 @@ import (
"strconv"
"strings"
"time"
"github.com/google/shlex"
)
func handleCGI(config Config, path string, cgiPath string, URL *url.URL, log *LogEntry, errorLog *log.Logger, conn net.Conn) {
@ -52,12 +50,7 @@ func handleCGI(config Config, path string, cgiPath string, URL *url.URL, log *Lo
// Use the CGICommand if provided
var script []string
if config.CGICommand != "" {
spl, err := shlex.Split(config.CGICommand)
if err != nil {
errorLog.Printf("Failed to split CGICommand: %s\n", err.Error())
return
}
script = spl
script = append([]string{config.CGICommand}, config.cgiCommandArgs...)
} else {
script = []string{scriptPath}
}