From 4e57fa0557593aea5f1b8fdd26d64c09e81a108c Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Tue, 9 Feb 2016 19:26:31 -0800 Subject: [PATCH] Fixed #360 Signed-off-by: Vishal Rana --- context.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/context.go b/context.go index 5cb07e05..c68ff4bd 100644 --- a/context.go +++ b/context.go @@ -159,10 +159,7 @@ func (c *Context) JSON(code int, i interface{}) (err error) { if err != nil { return err } - c.response.Header().Set(ContentType, ApplicationJSONCharsetUTF8) - c.response.WriteHeader(code) - c.response.Write(b) - return + return c.JSONBlob(code, b) } // JSONIndent sends a JSON response with status code, but it applies prefix and indent to format the output. @@ -171,14 +168,15 @@ func (c *Context) JSONIndent(code int, i interface{}, prefix string, indent stri if err != nil { return err } - c.json(code, b) - return + return c.JSONBlob(code, b) } -func (c *Context) json(code int, b []byte) { +// JSONBlob sends a JSON blob response with status code. +func (c *Context) JSONBlob(code int, b []byte) (err error) { c.response.Header().Set(ContentType, ApplicationJSONCharsetUTF8) c.response.WriteHeader(code) c.response.Write(b) + return } // JSONP sends a JSONP response with status code. It uses `callback` to construct