From aadd33af2c277718817d90de5ef935ff06923815 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Sat, 5 Jul 2014 02:53:51 +0200 Subject: [PATCH] Context.Data() takes content-type --- gin.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gin.go b/gin.go index fc49c83..a407ddb 100644 --- a/gin.go +++ b/gin.go @@ -480,7 +480,12 @@ func (c *Context) String(code int, msg string) { } // Writes some data into the body stream and updates the HTTP code. -func (c *Context) Data(code int, data []byte) { - c.Writer.WriteHeader(code) +func (c *Context) Data(code int, contentType string, data []byte) { + if len(contentType) > 0 { + c.Writer.Header().Set("Content-Type", contentType) + } + if code >= 0 { + c.Writer.WriteHeader(code) + } c.Writer.Write(data) }