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)