Defer sending log entry to channel.
This commit is contained in:
parent
dc92fbd228
commit
b4cbd47bce
1 changed files with 1 additions and 6 deletions
|
@ -10,12 +10,12 @@ import (
|
|||
|
||||
func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry) {
|
||||
defer conn.Close()
|
||||
|
||||
var log LogEntry
|
||||
log.Time = time.Now()
|
||||
log.RemoteAddr = conn.RemoteAddr()
|
||||
log.RequestURL = "-"
|
||||
log.Status = 0
|
||||
defer func() { logEntries <- log }()
|
||||
|
||||
// Read request
|
||||
reader := bufio.NewReaderSize(conn, 1024)
|
||||
|
@ -23,12 +23,10 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||
if overflow {
|
||||
conn.Write([]byte("59 Request too long!r\n"))
|
||||
log.Status = 59
|
||||
logEntries <- log
|
||||
return
|
||||
} else if err != nil {
|
||||
conn.Write([]byte("40 Unknown error reading request!r\n"))
|
||||
log.Status = 40
|
||||
logEntries <- log
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -37,7 +35,6 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||
if err != nil {
|
||||
conn.Write([]byte("59 Error parsing URL!r\n"))
|
||||
log.Status = 59
|
||||
logEntries <- log
|
||||
return
|
||||
}
|
||||
log.RequestURL = URL.String()
|
||||
|
@ -51,7 +48,6 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||
if URL.Scheme != "gemini" {
|
||||
conn.Write([]byte("53 No proxying to non-Gemini content!\r\n"))
|
||||
log.Status = 53
|
||||
logEntries <- log
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -60,5 +56,4 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||
body := fmt.Sprintf("Molly at %s says \"Hi!\" from %s.\n", URL.Host, URL.Path)
|
||||
conn.Write([]byte(body))
|
||||
log.Status = 20
|
||||
logEntries <- log
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue