46cde6e5 by astaxie

Merge pull request #683 from chrisport/develop

beego/context: Fix ignored Header in case SetStatus has been called before
2 parents fefd8ddb 3bb4d6f0
...@@ -71,6 +71,14 @@ func (output *BeegoOutput) Body(content []byte) { ...@@ -71,6 +71,14 @@ func (output *BeegoOutput) Body(content []byte) {
71 } else { 71 } else {
72 output.Header("Content-Length", strconv.Itoa(len(content))) 72 output.Header("Content-Length", strconv.Itoa(len(content)))
73 } 73 }
74
75 // Write status code if it has been set manually
76 // Set it to 0 afterwards to prevent "multiple response.WriteHeader calls"
77 if output.Status != 0 {
78 output.Context.ResponseWriter.WriteHeader(output.Status)
79 output.Status = 0
80 }
81
74 output_writer.Write(content) 82 output_writer.Write(content)
75 switch output_writer.(type) { 83 switch output_writer.(type) {
76 case *gzip.Writer: 84 case *gzip.Writer:
...@@ -270,7 +278,6 @@ func (output *BeegoOutput) ContentType(ext string) { ...@@ -270,7 +278,6 @@ func (output *BeegoOutput) ContentType(ext string) {
270 // SetStatus sets response status code. 278 // SetStatus sets response status code.
271 // It writes response header directly. 279 // It writes response header directly.
272 func (output *BeegoOutput) SetStatus(status int) { 280 func (output *BeegoOutput) SetStatus(status int) {
273 output.Context.ResponseWriter.WriteHeader(status)
274 output.Status = status 281 output.Status = status
275 } 282 }
276 283
......
...@@ -762,6 +762,11 @@ Admin: ...@@ -762,6 +762,11 @@ Admin:
762 Info("beego:" + r.URL.Path + " 404" + " +" + timeend.String()) 762 Info("beego:" + r.URL.Path + " 404" + " +" + timeend.String())
763 } 763 }
764 } 764 }
765
766 // Call WriteHeader if status code has been set changed
767 if context.Output.Status != 0 {
768 w.writer.WriteHeader(context.Output.Status)
769 }
765 } 770 }
766 771
767 func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Request) { 772 func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Request) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!