Skip to content

Commit 608cebb

Browse files
jszwedkovishr
authored andcommitted
Assign new ResponseWriter after calling http.HandlerFunc (#1341)
Otherwise, the `http.ResponseWriter` passed to `next()` within the middleware is unused. This precludes middlewares from wrapping the http.ResponseWriter to do things like record the status code.
1 parent 09d415c commit 608cebb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

context.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type (
2626
// SetRequest sets `*http.Request`.
2727
SetRequest(r *http.Request)
2828

29+
// SetResponse sets `*Response`.
30+
SetResponse(r *Response)
31+
2932
// Response returns `*Response`.
3033
Response() *Response
3134

@@ -228,6 +231,10 @@ func (c *context) Response() *Response {
228231
return c.response
229232
}
230233

234+
func (c *context) SetResponse(r *Response) {
235+
c.response = r
236+
}
237+
231238
func (c *context) IsTLS() bool {
232239
return c.request.TLS != nil
233240
}

echo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ func WrapMiddleware(m func(http.Handler) http.Handler) MiddlewareFunc {
767767
return func(c Context) (err error) {
768768
m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
769769
c.SetRequest(r)
770+
c.SetResponse(NewResponse(w, c.Echo()))
770771
err = next(c)
771772
})).ServeHTTP(c.Response(), c.Request())
772773
return

0 commit comments

Comments
 (0)