Commit 5d531d3d authored by lw's avatar lw

fix jsonp, use Buffer

parent ea756b68
...@@ -227,10 +227,13 @@ func (c *Controller) ServeJsonp() { ...@@ -227,10 +227,13 @@ func (c *Controller) ServeJsonp() {
http.Error(c.Ctx.ResponseWriter, `"callback" parameter required`, http.StatusInternalServerError) http.Error(c.Ctx.ResponseWriter, `"callback" parameter required`, http.StatusInternalServerError)
return return
} }
callback_content := fmt.Sprintf("%s(%s);\r\n", callback, string(content)) callback_content := bytes.NewBufferString(callback)
c.Ctx.SetHeader("Content-Length", strconv.Itoa(len(callback_content)), true) callback_content.WriteString("(")
c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/jsonp;charset=UTF-8") callback_content.Write(content)
c.Ctx.ResponseWriter.Write([]byte(callback_content)) callback_content.WriteString(");\r\n")
c.Ctx.SetHeader("Content-Length", strconv.Itoa(callback_content.Len()), true)
c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/json;charset=UTF-8")
c.Ctx.ResponseWriter.Write(callback_content.Bytes())
} }
func (c *Controller) ServeXml() { func (c *Controller) ServeXml() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment