mirror of
https://github.com/astaxie/beego.git
synced 2025-07-26 23:15:30 +00:00
beego/context: Fix ignored Header in case SetStatus has been called before
This commit is contained in:
@@ -71,6 +71,14 @@ func (output *BeegoOutput) Body(content []byte) {
|
||||
} else {
|
||||
output.Header("Content-Length", strconv.Itoa(len(content)))
|
||||
}
|
||||
|
||||
// Write status code if it has been set manually
|
||||
// Set it to 0 afterwards to prevent "multiple response.WriteHeader calls"
|
||||
if output.Status != 0 {
|
||||
output.Context.ResponseWriter.WriteHeader(output.Status)
|
||||
output.Status = 0
|
||||
}
|
||||
|
||||
output_writer.Write(content)
|
||||
switch output_writer.(type) {
|
||||
case *gzip.Writer:
|
||||
@@ -270,7 +278,6 @@ func (output *BeegoOutput) ContentType(ext string) {
|
||||
// SetStatus sets response status code.
|
||||
// It writes response header directly.
|
||||
func (output *BeegoOutput) SetStatus(status int) {
|
||||
output.Context.ResponseWriter.WriteHeader(status)
|
||||
output.Status = status
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user