Explorar o código

Do not update header when status code is less than 1

Manu Mtz-Almeida %!s(int64=11) %!d(string=hai) anos
pai
achega
4b62957d85
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      gin.go

+ 3 - 1
gin.go

@@ -344,7 +344,9 @@ func (c *Context) HTML(code int, name string, data interface{}) {
 
 // Writes the given string into the response body and sets the Content-Type to "text/plain"
 func (c *Context) String(code int, msg string) {
-	c.Writer.WriteHeader(code)
+	if code >= 0 {
+		c.Writer.WriteHeader(code)
+	}
 	c.Writer.Header().Set("Content-Type", "text/plain")
 	c.Writer.Write([]byte(msg))
 }