Stub implementation of SCGI.

This commit is contained in:
Solderpunk 2020-06-04 20:41:40 +02:00
parent 44d72c2bf2
commit 920f06597f
2 changed files with 16 additions and 0 deletions

View File

@ -13,6 +13,7 @@ type Config struct {
HomeDocBase string
LogPath string
CGIPath string
SCGIPaths map[string]string
}
func getConfig(filename string) (Config, error) {
@ -28,6 +29,7 @@ func getConfig(filename string) (Config, error) {
config.HomeDocBase = "users"
config.LogPath = "molly.log"
config.CGIPath = "^/var/gemini/cgi-bin/"
config.SCGIPaths = make(map[string]string)
// Return defaults if no filename given
if filename == "" {

View File

@ -77,6 +77,15 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
return
}
// Check whether this URL is mapped to an SCGI app
for scgi_url, scgi_socket := range config.SCGIPaths {
fmt.Println(scgi_url, URL.Path)
matched, err := regexp.Match(scgi_url, []byte(URL.Path))
if matched && err == nil {
fmt.Println("Matched:", scgi_url, scgi_socket)
handleSCGI(URL, log, conn)
return
}
}
// Resolve URI path to actual filesystem path
@ -233,3 +242,8 @@ func handleCGI(path string, URL *url.URL, log LogEntry, conn net.Conn) {
conn.Write(response)
}
func handleSCGI(URL *url.URL, log LogEntry, conn net.Conn) {
conn.Write([]byte("42 SCGI is only stubbed!\r\n"))
log.Status = 42
return
}