diff --git a/commands/http/handler.go b/commands/http/handler.go index 03ef39099..46be09e49 100644 --- a/commands/http/handler.go +++ b/commands/http/handler.go @@ -7,6 +7,8 @@ import ( "io" "net/http" "net/url" + "os" + "runtime" "strconv" "strings" @@ -103,6 +105,16 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Debug("Incoming API request: ", r.URL) + defer func() { + if r := recover(); r != nil { + log.Error(r) + + buf := make([]byte, 4096) + n := runtime.Stack(buf, false) + fmt.Fprintln(os.Stderr, string(buf[:n])) + } + }() + if !allowOrigin(r, i.cfg) || !allowReferer(r, i.cfg) { w.WriteHeader(http.StatusForbidden) w.Write([]byte("403 - Forbidden"))