fix jsonp, use Buffer
Showing
1 changed file
with
7 additions
and
4 deletions
| ... | @@ -227,10 +227,13 @@ func (c *Controller) ServeJsonp() { | ... | @@ -227,10 +227,13 @@ func (c *Controller) ServeJsonp() { |
| 227 | http.Error(c.Ctx.ResponseWriter, `"callback" parameter required`, http.StatusInternalServerError) | 227 | http.Error(c.Ctx.ResponseWriter, `"callback" parameter required`, http.StatusInternalServerError) |
| 228 | return | 228 | return |
| 229 | } | 229 | } |
| 230 | callback_content := fmt.Sprintf("%s(%s);\r\n", callback, string(content)) | 230 | callback_content := bytes.NewBufferString(callback) |
| 231 | c.Ctx.SetHeader("Content-Length", strconv.Itoa(len(callback_content)), true) | 231 | callback_content.WriteString("(") |
| 232 | c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/jsonp;charset=UTF-8") | 232 | callback_content.Write(content) |
| 233 | c.Ctx.ResponseWriter.Write([]byte(callback_content)) | 233 | callback_content.WriteString(");\r\n") |
| 234 | c.Ctx.SetHeader("Content-Length", strconv.Itoa(callback_content.Len()), true) | ||
| 235 | c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/json;charset=UTF-8") | ||
| 236 | c.Ctx.ResponseWriter.Write(callback_content.Bytes()) | ||
| 234 | } | 237 | } |
| 235 | 238 | ||
| 236 | func (c *Controller) ServeXml() { | 239 | func (c *Controller) ServeXml() { | ... | ... |
-
Please register or sign in to post a comment