title: Content Type of POST request payload
body: <p>I am sending a JSON body in my POST Request, but http.DetectContentType is identifying it as a text/plain type.</p>
  
  <p>I want to have flexibility to process request payload based on their content type - if XML {}  if JSON {} else {NO Processing} </p>
  
  <p>To achieve this conditional processing, I am using http.DetectContentType to return the content type o the request but it is returning text/plain is every scenario.</p>
  
  <pre><code>func Test(w http.ResponseWriter, r *http.Request) *ErrorObject {
  
          reqBuffer := make([]byte, 512)
          _, err := r.Body.Read(reqBuffer)
          if err != nil {
  
      return ErrorObject{}.New(1, err, nil)
  }
  
  contentType := GetContentType(reqBuffer)
  fmt.Printf(contentType)
  
      if contentType == "application/xml" || contentType == "text/xml" {
      w.Header().Set("Content-Type", "application/xml; charset=UTF-8") ...}
      if contentType == "application/json" || contentType == "text/json" {
      w.Header().Set("Content-Type", "application/json; charset=UTF-8") ... } 
      else return Invalid Request Type error
  } 
  
     func GetContentType(buffer []byte) string {
  
         fmt.Println(string(buffer))
         contentType := http.DetectContentType(buffer)
         fmt.Printf(contentType)
         return contentType
  
      }
  </code></pre>
  
  <p>Expect to return the function - Content Type as application/json but getting text/plain </p>
  
  <p>Using POSTMAN to send request to server with Body as raw and JSON</p>
  
  <pre><code>    {
        "data": [
           {
             "group": "TEST",
             "name": "TEST",
             "released": true,
             "version": 1,
             "teststeps": [
                {
                     "bin": 32,
                     "comment": "PAA",
                     "dataType": "J",
                     "format": "R6.2",
                     "id": "PAA3",
                     "osg": 8,
                     "usg": 0
                }
              ],
             "parameters": [
                {
                    "comment": "test",
                    "description": "test",
                    "format": "R7.0",
                    "id": 1,
                    "teststepId": "PAA",
                    "value": 30,
                    "type": "teststep"
              }
            ]
          }
       ]
    }
  </code></pre>