From 5f2670fddefae16375979e1dd5e84dc2124023a8 Mon Sep 17 00:00:00 2001 From: Jason Chu Date: Sat, 20 Feb 2016 00:42:17 +0800 Subject: [PATCH] Fix missing Content-Type for certain errors And corrected an error in a copy and pasted comment --- caddy/setup/errors.go | 2 +- middleware/errors/errors.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/caddy/setup/errors.go b/caddy/setup/errors.go index 24e2b0bb..b4c0ab69 100644 --- a/caddy/setup/errors.go +++ b/caddy/setup/errors.go @@ -12,7 +12,7 @@ import ( "github.com/mholt/caddy/middleware/errors" ) -// Errors configures a new gzip middleware instance. +// Errors configures a new errors middleware instance. func Errors(c *Controller) (middleware.Middleware, error) { handler, err := errorsParse(c) if err != nil { diff --git a/middleware/errors/errors.go b/middleware/errors/errors.go index e9eef90e..33a15269 100644 --- a/middleware/errors/errors.go +++ b/middleware/errors/errors.go @@ -34,6 +34,7 @@ func (h ErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er if h.Debug { // Write error to response instead of to log + w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.WriteHeader(status) fmt.Fprintln(w, errMsg) return 0, err // returning < 400 signals that a response has been written @@ -124,6 +125,7 @@ func (h ErrorHandler) recovery(w http.ResponseWriter, r *http.Request) { // Write error and stack trace to the response rather than to a log var stackBuf [4096]byte stack := stackBuf[:runtime.Stack(stackBuf[:], false)] + w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.WriteHeader(http.StatusInternalServerError) fmt.Fprintf(w, "%s\n\n%s", panicMsg, stack) } else {