From 920f06597f91c83001abe1951b532f1605a1ad14 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Thu, 4 Jun 2020 20:41:40 +0200 Subject: [PATCH] Stub implementation of SCGI. --- config.go | 2 ++ handler.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/config.go b/config.go index 13020b3..7acd510 100644 --- a/config.go +++ b/config.go @@ -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 == "" { diff --git a/handler.go b/handler.go index b1b283e..98d4301 100644 --- a/handler.go +++ b/handler.go @@ -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 +}