mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-21 01:45:45 +03:00
errors: Pointer to handler prevents nil pointer errors in handling (fixes #15)
If we do not use a pointer here, the startup function that opens the log file stores the log file in a copy of the handler, not the same instance of the handler, causing panics during requests, which is bad, especially when the response is gzipped: the next recover() is beyond the gzip handler, so the browser downloads a gz file instead.
This commit is contained in:
parent
b1e1caba29
commit
9dfbbbcda4
1 changed files with 5 additions and 2 deletions
|
@ -113,8 +113,11 @@ func (h ErrorHandler) errorPage(w http.ResponseWriter, code int) {
|
||||||
http.Error(w, defaultBody, code)
|
http.Error(w, defaultBody, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse(c middleware.Controller) (ErrorHandler, error) {
|
func parse(c middleware.Controller) (*ErrorHandler, error) {
|
||||||
handler := ErrorHandler{ErrorPages: make(map[int]string)}
|
// Very important that we make a pointer because the Startup
|
||||||
|
// function that opens the log file must have access to the
|
||||||
|
// same instance of the handler, not a copy.
|
||||||
|
handler := &ErrorHandler{ErrorPages: make(map[int]string)}
|
||||||
|
|
||||||
optionalBlock := func() (bool, error) {
|
optionalBlock := func() (bool, error) {
|
||||||
var hadBlock bool
|
var hadBlock bool
|
||||||
|
|
Loading…
Reference in a new issue