Skip to content

Commit

Permalink
Prevent superfluous response.WriteHeader (go-gitea#15456) (go-gitea#1…
Browse files Browse the repository at this point in the history
…5476)

Backport go-gitea#15456

This PR simply checks the status before writing the header.

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath authored Apr 15, 2021
1 parent b28c324 commit 00e55dd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions modules/context/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package context

import "net/http"
import (
"net/http"
)

// ResponseWriter represents a response writer for HTTP
type ResponseWriter interface {
Expand Down Expand Up @@ -60,8 +62,10 @@ func (r *Response) WriteHeader(statusCode int) {
}
r.beforeExecuted = true
}
r.status = statusCode
r.ResponseWriter.WriteHeader(statusCode)
if r.status == 0 {
r.status = statusCode
r.ResponseWriter.WriteHeader(statusCode)
}
}

// Flush flush cached data
Expand Down

0 comments on commit 00e55dd

Please sign in to comment.