WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
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