title: Go http context not able to capture cancellation signal when request has body (curl, postman)
body: <p>The problem can be reproduced with the below simple go code snippet：</p>
  
  <p>Simple go http server:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "log"
      "net/http"
      "time"
  )
  
  func handler(w http.ResponseWriter, r *http.Request) {
      go func(done &lt;-chan struct{}) {
          &lt;-done
          fmt.Println("message", "client connection has gone away, request got cancelled")
      }(r.Context().Done())
  
      time.Sleep(30 * time.Second)
      fmt.Fprintf(w, "Hi there, I love %s!\n", r.URL.Path[1:])
  }
  
  func main() {
      http.HandleFunc("/", handler)
      log.Fatal(http.ListenAndServe(":8080", nil))
  }
  </code></pre>
  
  <p>Start above http server, if i send one simple <code>GET</code> request with curl(postman also) like:</p>
  
  <pre><code>curl -X GET http://localhost:8080/
  </code></pre>
  
  <p>then press <code>Ctrl+C</code> to terminate the request, then i am able to see the printed message at server side:</p>
  
  <pre><code>message client connection has gone away, request got cancelled
  </code></pre>
  
  <p><strong>above is the correct behaviour i expect</strong>: to simulate the situation that when client is gone the server can capture it and then cancel all the unnecessary work as early as it can.</p>
  
  <p>But when i send one POST request with request body, this expected behaviour <strong>doesn't</strong> happen, the <code>&lt;-done</code> signal was captured until the request deadline meet.</p>
  
  <pre><code>curl -X POST http://localhost:8080/ -H 'Content-Type: application/json' -d '{}'
  </code></pre>
  
  <p>To summarize my questions:</p>
  
  <ol>
  <li>Why and how the curl(postman) <code>GET</code>, <code>POST</code> (with or without request body) request make such a difference?</li>
  <li>How should i handle this case properly with go context package, i mean to capture the client is gone signal as soon as it can, and so further to cancel the server side unnecessary work to release the resources as early as it can.</li>
  </ol>