Fix crash when CGI processes end without writing anything at all to stdout. Closes #38.
This commit is contained in:
parent
4b54eb6134
commit
2c3225c1c0
1 changed files with 11 additions and 3 deletions
14
dynamic.go
14
dynamic.go
|
@ -73,15 +73,23 @@ func handleCGI(config SysConfig, path string, cgiPath string, URL *url.URL, logE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Extract response header
|
// Extract response header
|
||||||
header, _, err := bufio.NewReader(strings.NewReader(string(response))).ReadLine()
|
responseString := string(response)
|
||||||
status, err2 := strconv.Atoi(strings.Fields(string(header))[0])
|
if len(responseString) == 0 {
|
||||||
if err != nil || err2 != nil {
|
log.Println("Received no response from CGI process " + path)
|
||||||
|
conn.Write([]byte("42 CGI error!\r\n"))
|
||||||
|
logEntry.Status = 42
|
||||||
|
return
|
||||||
|
}
|
||||||
|
header, _, _ := bufio.NewReader(strings.NewReader(string(response))).ReadLine()
|
||||||
|
status, err := strconv.Atoi(strings.Fields(string(header))[0])
|
||||||
|
if err != nil {
|
||||||
log.Println("Unable to parse first line of output from CGI process " + path + " as valid Gemini response header. Line was: " + string(header))
|
log.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"))
|
||||||
logEntry.Status = 42
|
logEntry.Status = 42
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logEntry.Status = status
|
logEntry.Status = status
|
||||||
|
|
||||||
// Write response
|
// Write response
|
||||||
conn.Write(response)
|
conn.Write(response)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue