Skip to content

Commit

Permalink
handler, http: have ContentEncode not write anything if there is no o…
Browse files Browse the repository at this point in the history
…utput to encode
  • Loading branch information
lithdew committed May 13, 2020
1 parent 259f156 commit d5c2597
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))})
}

Expand Down

0 comments on commit d5c2597

Please sign in to comment.