File tree 1 file changed +7
-1
lines changed
1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -116,13 +116,19 @@ func (t echoHandlerFuncWrapper) ServeHTTP(rw http.ResponseWriter, r *http.Reques
116
116
// we restore original writer only for cases we did not timeout. On timeout we have already sent response to client
117
117
// and should not anymore send additional headers/data
118
118
// so on timeout writer stays what http.TimeoutHandler uses and prevents writing headers/body
119
- t .ctx .Response ().Writer = originalWriter
119
+ // https://github.com/labstack/echo/issues/1905
120
+ // error handling is a part of processes in Echo handler, if a handler returns an error
121
+ // and if it did not timeout, the global error handler shall act on rw (`http.timeoutWriter` in our case)
122
+ // to avoid superfluous response.WriteHeader call
120
123
if err != nil {
121
124
// call global error handler to write error to the client. This is needed or `http.TimeoutHandler` will send status code by itself
122
125
// and after that our tries to write status code will not work anymore
123
126
t .ctx .Error (err )
124
127
// we pass error from handler to middlewares up in handler chain to act on it if needed. But this means that
125
128
// global error handler is probably be called twice as `t.ctx.Error` already does that.
129
+ // NB: later call of thr global error handler will not take any effect, as echo.Response will be marked as `committed`
130
+ // when the first call take place.
131
+ t .ctx .Response ().Writer = originalWriter
126
132
t .errChan <- err
127
133
}
128
134
}
You can’t perform that action at this time.
0 commit comments