mirror of
https://github.com/labstack/echo.git
synced 2025-07-03 00:56:59 +02:00
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.
This commit is contained in:
committed by
Vishal Rana
parent
09d415cefc
commit
608cebbaae
@ -26,6 +26,9 @@ type (
|
|||||||
// SetRequest sets `*http.Request`.
|
// SetRequest sets `*http.Request`.
|
||||||
SetRequest(r *http.Request)
|
SetRequest(r *http.Request)
|
||||||
|
|
||||||
|
// SetResponse sets `*Response`.
|
||||||
|
SetResponse(r *Response)
|
||||||
|
|
||||||
// Response returns `*Response`.
|
// Response returns `*Response`.
|
||||||
Response() *Response
|
Response() *Response
|
||||||
|
|
||||||
@ -228,6 +231,10 @@ func (c *context) Response() *Response {
|
|||||||
return c.response
|
return c.response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *context) SetResponse(r *Response) {
|
||||||
|
c.response = r
|
||||||
|
}
|
||||||
|
|
||||||
func (c *context) IsTLS() bool {
|
func (c *context) IsTLS() bool {
|
||||||
return c.request.TLS != nil
|
return c.request.TLS != nil
|
||||||
}
|
}
|
||||||
|
1
echo.go
1
echo.go
@ -767,6 +767,7 @@ func WrapMiddleware(m func(http.Handler) http.Handler) MiddlewareFunc {
|
|||||||
return func(c Context) (err error) {
|
return func(c Context) (err error) {
|
||||||
m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
c.SetRequest(r)
|
c.SetRequest(r)
|
||||||
|
c.SetResponse(NewResponse(w, c.Echo()))
|
||||||
err = next(c)
|
err = next(c)
|
||||||
})).ServeHTTP(c.Response(), c.Request())
|
})).ServeHTTP(c.Response(), c.Request())
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user