1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 11:20:56 +00:00

return write body error

This commit is contained in:
ysqi 2016-02-12 11:36:25 +08:00
parent 810f6db8d2
commit d35c50a8e0
2 changed files with 7 additions and 10 deletions

View File

@ -56,7 +56,7 @@ func (output *BeegoOutput) Header(key, val string) {
// Body sets response body content. // Body sets response body content.
// if EnableGzip, compress content string. // if EnableGzip, compress content string.
// it sends out response body directly. // it sends out response body directly.
func (output *BeegoOutput) Body(content []byte) { func (output *BeegoOutput) Body(content []byte) error {
var encoding string var encoding string
var buf = &bytes.Buffer{} var buf = &bytes.Buffer{}
if output.EnableGzip { if output.EnableGzip {
@ -74,7 +74,8 @@ func (output *BeegoOutput) Body(content []byte) {
output.Status = 0 output.Status = 0
} }
output.Context.ResponseWriter.Copy(buf) _, err := output.Context.ResponseWriter.Copy(buf)
return err
} }
// Cookie sets cookie value via given key. // Cookie sets cookie value via given key.
@ -185,8 +186,7 @@ func (output *BeegoOutput) JSON(data interface{}, hasIndent bool, coding bool) e
if coding { if coding {
content = []byte(stringsToJSON(string(content))) content = []byte(stringsToJSON(string(content)))
} }
output.Body(content) return output.Body(content)
return nil
} }
// JSONP writes jsonp to response body. // JSONP writes jsonp to response body.
@ -211,8 +211,7 @@ func (output *BeegoOutput) JSONP(data interface{}, hasIndent bool) error {
callbackContent.WriteString("(") callbackContent.WriteString("(")
callbackContent.Write(content) callbackContent.Write(content)
callbackContent.WriteString(");\r\n") callbackContent.WriteString(");\r\n")
output.Body(callbackContent.Bytes()) return output.Body(callbackContent.Bytes())
return nil
} }
// XML writes xml string to response body. // XML writes xml string to response body.
@ -229,8 +228,7 @@ func (output *BeegoOutput) XML(data interface{}, hasIndent bool) error {
http.Error(output.Context.ResponseWriter, err.Error(), http.StatusInternalServerError) http.Error(output.Context.ResponseWriter, err.Error(), http.StatusInternalServerError)
return err return err
} }
output.Body(content) return output.Body(content)
return nil
} }
// Download forces response for download file. // Download forces response for download file.

View File

@ -185,8 +185,7 @@ func (c *Controller) Render() error {
return err return err
} }
c.Ctx.Output.Header("Content-Type", "text/html; charset=utf-8") c.Ctx.Output.Header("Content-Type", "text/html; charset=utf-8")
c.Ctx.Output.Body(rb) return c.Ctx.Output.Body(rb)
return nil
} }
// RenderString returns the rendered template string. Do not send out response. // RenderString returns the rendered template string. Do not send out response.