From 5d531d3da63d932ff4b6536a843e15b9f2190c1d Mon Sep 17 00:00:00 2001 From: lw Date: Fri, 14 Jun 2013 09:39:56 +0800 Subject: [PATCH] fix jsonp, use Buffer --- controller.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/controller.go b/controller.go index 359121eb..3b520749 100644 --- a/controller.go +++ b/controller.go @@ -227,10 +227,13 @@ func (c *Controller) ServeJsonp() { http.Error(c.Ctx.ResponseWriter, `"callback" parameter required`, http.StatusInternalServerError) return } - callback_content := fmt.Sprintf("%s(%s);\r\n", callback, string(content)) - c.Ctx.SetHeader("Content-Length", strconv.Itoa(len(callback_content)), true) - c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/jsonp;charset=UTF-8") - c.Ctx.ResponseWriter.Write([]byte(callback_content)) + callback_content := bytes.NewBufferString(callback) + callback_content.WriteString("(") + callback_content.Write(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() {