golang gin gonic content-type not setting to application/json with c.JSON
<p>According to the <a href="https://gowalker.org/github.com/gin-gonic/gin#Context_JSON" rel="nofollow noreferrer">official documentation</a>, c.JSON of <a href="https://github.com/gin-gonic/gin" rel="nofollow noreferrer">gin-gonic</a> should set the response header to <code>application/json</code>, but when I call my API from <a href="https://www.getpostman.com/" rel="nofollow noreferrer">Postman</a>, the response header is set to <code>text/plain; charset=utf-8</code></p>

<p>I don't understand what I am missing, any idea ?</p>

<p>Doc :</p>

<blockquote>
  <p><strong>func JSON</strong></p>
  
  <p>JSON serializes the given struct as JSON into the response body. It
  also sets the Content-Type as "application/json".</p>
</blockquote>

<p>Here is a sample of my code :</p>

<pre><code>func postLogin(c *gin.Context) {
    var credentials DTO.Credentials
    if err := c.BindJSON(&amp;credentials); err == nil {
        c.JSON(buildResponse(services.CheckUserCredentials(credentials)))
    } else {
        var apiErrors = DTO.ApiErrors{}
        for _, v := range err.(validator.ValidationErrors) {
            apiErrors.Errors = append(apiErrors.Errors, DTO.ApiError{Field: v.Field, Message: v.Field + " is " + v.Tag})
        }
        c.JSON(http.StatusBadRequest, apiErrors)
    }
}
</code></pre>

<p><strong>EDIT</strong></p>

<p>After investigation, log.Println(c.Writer.Header().Get("Content-Type")) doesn't print any thing, showing content-type is empty as it should be.</p>

<pre><code>func writeContentType(w http.ResponseWriter, value []string) {
    header := w.Header()
    log.Println(header.Get("Content-Type")) // &lt;=========== Nothing happen
    if val := header["Content-Type"]; len(val) == 0 {
        header["Content-Type"] = value
    }
}
</code></pre>

<p>I really don't want to have to add <code>c.Writer.Header().Set("Content-Type", "application/json")</code> to every route in my architecture...</p>

<p><strong>EDIT 2</strong></p>

<p>It seems like <code>binding:"required"</code> break the Content-Type Header</p>

<pre><code>type Credentials struct {
    Email         string        `json:"email" binding:"required"`
    Password      string        `json:"password" binding:"required"`
}
</code></pre>