From d5c2597f1eb0464904587a1306d86bb45871e361 Mon Sep 17 00:00:00 2001 From: Kenta Iwasaki Date: Thu, 14 May 2020 03:07:07 +0900 Subject: [PATCH] handler, http: have ContentEncode not write anything if there is no output to encode --- handler.go | 4 ++++ http.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/handler.go b/handler.go index f779728..e6ff15f 100644 --- a/handler.go +++ b/handler.go @@ -154,6 +154,10 @@ func getBodyParams(r *http.Request, codec *Codec, values map[string]interface{}) type ContentEncode struct{} func (h *ContentEncode) Serve(ctx *Context, w http.ResponseWriter, _ *http.Request) error { + if len(ctx.Out) == 0 { + return nil + } + codec := ctx.Config.Codecs[w.Header().Get(HeaderContentType)] if codec == nil { diff --git a/http.go b/http.go index 1c2af8a..8822a84 100644 --- a/http.go +++ b/http.go @@ -108,7 +108,7 @@ func (s *Server) Shutdown() error { } func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { - s.handler(s.Before...).ServeHTTP(w, r) + s.handler(append(s.Before, s.After...)...).ServeHTTP(w, r) s.writeError(w, &Error{Status: http.StatusNotFound, Err: errors.New(http.StatusText(http.StatusNotFound))}) }