I'm trying to understand the purpose of an ErrorLog
struct field in http.Server
struct. By its name I suspect that those are some kind of errors, but which ones?
What would trigger errors being outputted there? Broken network? Too large http requests?
package main
import (
"log"
"net/http"
)
func main() {
_ = &http.Server{
ErrorLog: log.Default(), // what errors are outputted here?
}
}
The official documentation provides an overview of how the field is used:
// ErrorLog specifies an optional logger for errors accepting
// connections, unexpected behavior from handlers, and
// underlying FileSystem errors.
// If nil, logging is done via the log package's standard logger.
ErrorLog *log.Logger // Go 1.3
In practice, the field is accessed in the *http.Server
's logf
method. You can check where that method is called. In short (not exhaustive):
conn
's serve(ctx context.Context)
)Serve(l net.Listener) error
errorsContent-Length
is invalidWriteHeader(code int)
on the same response more than onceContent-Length
and non-identity
Transfer-Encoding
headers are used together