Skip to content

fixed issue #2791 Improved robustness of Response process and added debugging information #2792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func (r *Response) After(fn func()) {
// used to send error codes.
func (r *Response) WriteHeader(code int) {
if r.Committed {
r.echo.Logger.Warn("response already committed")
if r.echo != nil && r.echo.Logger != nil {
r.echo.Logger.Warn("response already committed")
}
return
}
r.Status = code
Expand Down Expand Up @@ -87,8 +89,15 @@ func (r *Response) Write(b []byte) (n int, err error) {
// See [http.Flusher](https://golang.org/pkg/net/http/#Flusher)
func (r *Response) Flush() {
err := http.NewResponseController(r.Writer).Flush()
if err != nil && errors.Is(err, http.ErrNotSupported) {
panic(errors.New("response writer flushing is not supported"))
if err != nil {
if errors.Is(err, http.ErrNotSupported) {
panic(errors.New("response writer flushing is not supported"))
}
// Log other flush errors if a logger is available and in debug mode,
// as http.Flusher interface does not allow returning an error.
if r.echo != nil && r.echo.Logger != nil && r.echo.Debug {
r.echo.Logger.Errorf("error during response flush: %v", err)
}
}
}

Expand Down