瀏覽代碼

Context.Data() takes content-type

Manu Mtz-Almeida 11 年之前
父節點
當前提交
aadd33af2c
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      gin.go

+ 7 - 2
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.
 // 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)
 	c.Writer.Write(data)
 }
 }