More and better error logging.
This commit is contained in:
parent
821a862036
commit
f7e588dfae
2 changed files with 13 additions and 8 deletions
|
@ -73,7 +73,7 @@ func handleCGI(config Config, path string, cgiPath string, URL *url.URL, log *Lo
|
||||||
header, _, err := bufio.NewReader(strings.NewReader(string(response))).ReadLine()
|
header, _, err := bufio.NewReader(strings.NewReader(string(response))).ReadLine()
|
||||||
status, err2 := strconv.Atoi(strings.Fields(string(header))[0])
|
status, err2 := strconv.Atoi(strings.Fields(string(header))[0])
|
||||||
if err != nil || err2 != nil {
|
if err != nil || err2 != nil {
|
||||||
errorLog.Println("Unable to parse first line of output from CGI process " + path + " as valid Gemini response header.")
|
errorLog.Println("Unable to parse first line of output from CGI process " + path + " as valid Gemini response header. Line was: " + string(header))
|
||||||
conn.Write([]byte("42 CGI error!\r\n"))
|
conn.Write([]byte("42 CGI error!\r\n"))
|
||||||
log.Status = 42
|
log.Status = 42
|
||||||
return
|
return
|
||||||
|
@ -83,11 +83,12 @@ func handleCGI(config Config, path string, cgiPath string, URL *url.URL, log *Lo
|
||||||
conn.Write(response)
|
conn.Write(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSCGI(URL *url.URL, scgiPath string, scgiSocket string, config Config, log *LogEntry, conn net.Conn) {
|
func handleSCGI(URL *url.URL, scgiPath string, scgiSocket string, config Config, log *LogEntry, errorLog *log.Logger, conn net.Conn) {
|
||||||
|
|
||||||
// Connect to socket
|
// Connect to socket
|
||||||
socket, err := net.Dial("unix", scgiSocket)
|
socket, err := net.Dial("unix", scgiSocket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
errorLog.Println("Error connecting to SCGI socket " + scgiSocket + ": " + err.Error())
|
||||||
conn.Write([]byte("42 Error connecting to SCGI service!\r\n"))
|
conn.Write([]byte("42 Error connecting to SCGI service!\r\n"))
|
||||||
log.Status = 42
|
log.Status = 42
|
||||||
return
|
return
|
||||||
|
@ -119,6 +120,7 @@ func handleSCGI(URL *url.URL, scgiPath string, scgiSocket string, config Config,
|
||||||
break
|
break
|
||||||
} else if !first {
|
} else if !first {
|
||||||
// Err
|
// Err
|
||||||
|
errorLog.Println("Error reading from SCGI socket " + scgiSocket + ": " + err.Error())
|
||||||
conn.Write([]byte("42 Error reading from SCGI service!\r\n"))
|
conn.Write([]byte("42 Error reading from SCGI service!\r\n"))
|
||||||
log.Status = 42
|
log.Status = 42
|
||||||
return
|
return
|
||||||
|
|
15
handler.go
15
handler.go
|
@ -86,7 +86,7 @@ func handleGeminiRequest(conn net.Conn, config Config, accessLogEntries chan Log
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for redirects
|
// Check for redirects
|
||||||
handleRedirects(URL, config, conn, &log)
|
handleRedirects(URL, config, conn, &log, errorLog)
|
||||||
if log.Status != 0 {
|
if log.Status != 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ func handleGeminiRequest(conn net.Conn, config Config, accessLogEntries chan Log
|
||||||
// Check whether this URL is mapped to an SCGI app
|
// Check whether this URL is mapped to an SCGI app
|
||||||
for scgiPath, scgiSocket := range config.SCGIPaths {
|
for scgiPath, scgiSocket := range config.SCGIPaths {
|
||||||
if strings.HasPrefix(URL.Path, scgiPath) {
|
if strings.HasPrefix(URL.Path, scgiPath) {
|
||||||
handleSCGI(URL, scgiPath, scgiSocket, config, &log, conn)
|
handleSCGI(URL, scgiPath, scgiSocket, config, &log, errorLog, conn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,7 @@ func handleGeminiRequest(conn net.Conn, config Config, accessLogEntries chan Log
|
||||||
log.Status = 51
|
log.Status = 51
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
errorLog.Println("Error getting info for file " + path + ": " + err.Error())
|
||||||
conn.Write([]byte("40 Temporary failure!\r\n"))
|
conn.Write([]byte("40 Temporary failure!\r\n"))
|
||||||
log.Status = 40
|
log.Status = 40
|
||||||
return
|
return
|
||||||
|
@ -239,16 +240,17 @@ func parseMollyFiles(path string, config *Config, errorLog *log.Logger) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRedirects(URL *url.URL, config Config, conn net.Conn, log *LogEntry) {
|
func handleRedirects(URL *url.URL, config Config, conn net.Conn, log *LogEntry, errorLog *log.Logger) {
|
||||||
handleRedirectsInner(URL, config.TempRedirects, 30, conn, log)
|
handleRedirectsInner(URL, config.TempRedirects, 30, conn, log, errorLog)
|
||||||
handleRedirectsInner(URL, config.PermRedirects, 31, conn, log)
|
handleRedirectsInner(URL, config.PermRedirects, 31, conn, log, errorLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRedirectsInner(URL *url.URL, redirects map[string]string, status int, conn net.Conn, log *LogEntry) {
|
func handleRedirectsInner(URL *url.URL, redirects map[string]string, status int, conn net.Conn, log *LogEntry, errorLog *log.Logger) {
|
||||||
strStatus := strconv.Itoa(status)
|
strStatus := strconv.Itoa(status)
|
||||||
for src, dst := range redirects {
|
for src, dst := range redirects {
|
||||||
compiled, err := regexp.Compile(src)
|
compiled, err := regexp.Compile(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
errorLog.Println("Error compiling redirect regexp " + src + ": " + err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if compiled.MatchString(URL.Path) {
|
if compiled.MatchString(URL.Path) {
|
||||||
|
@ -308,6 +310,7 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config, errorLo
|
||||||
|
|
||||||
contents, err := ioutil.ReadFile(path)
|
contents, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
errorLog.Println("Error reading file " + path + ": " + err.Error())
|
||||||
conn.Write([]byte("50 Error!\r\n"))
|
conn.Write([]byte("50 Error!\r\n"))
|
||||||
log.Status = 50
|
log.Status = 50
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue