Check for a CGI path prefix before insisting that an exact path exists on disk. Closes #36.

This commit is contained in:
Solderpunk 2023-03-16 19:23:32 +01:00
parent 72a94cab00
commit c4866d2965
1 changed files with 18 additions and 18 deletions

View File

@ -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)