title: Getting error on PUT "Body length 0" using net/http
body: <p>I am using this Go API client on my app <a href="https://github.com/heroku/docker-registry-client" rel="nofollow noreferrer">https://github.com/heroku/docker-registry-client</a> to interact with a docker registry using Go. The case is that internally that is having some issue when does a PUT request using the package "net/http".</p>
  
  <p>When I run the following code I am getting this as error <code>Put url: http: ContentLength=2821 with Body length 0</code>. So it seems that net/http Client.Do() function is not getting the body I set at some point of the function. But as you can se right on the code below at some point I still have the JSON content that I want to send in a <code>[]byte</code>. </p>
  
  <pre><code>body, err := manifest.MarshalJSON()
  if err != nil {
      return err
  }
  
  log.Println(string(body)) // I get the JSON data back here
  
  req, err := http.NewRequest("PUT", url, bytes.NewReader(body))
  if err != nil {
      return err
  }
  
  req.Header.Set("Content-Type", manifestV2.MediaTypeManifest)
  resp, err := registry.Client.Do(req)
  if resp != nil {
      defer resp.Body.Close()
  }
  return err
  </code></pre>
  
  <p>As far as I have digged into it, the error comes from the net/http <code>Client.do()</code> function (golang.org/src/net/http/client.go line 514), and I'd say the error is triggered from <code>Request.GetBody()</code> function (from line 591 on Client). </p>
  
  <p>So still trying to go deeper and do some tests to find out what is going on here. </p>
  
  <p>Any clue?</p>
  
  <p>In case the error is given by the server I'll have to get something like this, but in the response body and no errors on the net/http <code>Client.Do()</code> call.</p>
  
  <pre><code>Content-Length: &lt;length&gt;
  Content-Type: application/json; charset=utf-8
  
  {
      "errors:" [
          {
              "code": &lt;error code&gt;,
              "message": "&lt;error message&gt;",
              "detail": ...
          },
          ...
      ]
  }
  </code></pre>
  
  <p>Thank you so much!</p>
  
  <p>Cheers</p>