From c4866d296502bda8dc5018393b95be53f891ac6f Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Thu, 16 Mar 2023 19:23:32 +0100 Subject: [PATCH] Check for a CGI path prefix before insisting that an exact path exists on disk. Closes #36. --- handler.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/handler.go b/handler.go index 681e317..b1018c7 100644 --- a/handler.go +++ b/handler.go @@ -100,14 +100,6 @@ func handleGeminiRequest(conn net.Conn, sysConfig SysConfig, config UserConfig, return } - // Check whether this URL is mapped to an SCGI app - for scgiPath, scgiSocket := range sysConfig.SCGIPaths { - if strings.HasPrefix(URL.Path, scgiPath) { - handleSCGI(URL, scgiPath, scgiSocket, sysConfig, &logEntry, conn) - return - } - } - // Resolve URI path to actual filesystem path path := resolvePath(URL.Path, sysConfig) @@ -128,6 +120,24 @@ func handleGeminiRequest(conn net.Conn, sysConfig SysConfig, config UserConfig, } } + // Check whether this URL is in a configured CGI path + for _, cgiPath := range sysConfig.CGIPaths { + if strings.HasPrefix(path, cgiPath) { + handleCGI(sysConfig, path, cgiPath, URL, &logEntry, conn) + if logEntry.Status != 0 { + return + } + } + } + + // Check whether this URL is mapped to an SCGI app + for scgiPath, scgiSocket := range sysConfig.SCGIPaths { + if strings.HasPrefix(URL.Path, scgiPath) { + handleSCGI(URL, scgiPath, scgiSocket, sysConfig, &logEntry, conn) + return + } + } + // Okay, at this point we really are committed to looking on disk for `path`. // Make sure it exists, and is world readable, and if it's a symbolic link, // follow it and check these things again! @@ -185,16 +195,6 @@ func handleGeminiRequest(conn net.Conn, sysConfig SysConfig, config UserConfig, return } - // Check whether this URL is in a configured CGI path - for _, cgiPath := range sysConfig.CGIPaths { - if strings.HasPrefix(path, cgiPath) { - handleCGI(sysConfig, path, cgiPath, URL, &logEntry, conn) - if logEntry.Status != 0 { - return - } - } - } - // Finally, serve a simple static file or directory if info.IsDir() { serveDirectory(URL, path, &logEntry, conn, config)