title: How to check if a request was cancelled
body: <p>I have this simple code in which I try to check if the request was cancelled. But surprisingly, it prints <code>false</code> instead of <code>true</code> in go 1.9.</p>
  
  <p>I wonder what's the correct way to check that?</p>
  
  <pre><code>package main
  
  import (
      "context"
      "log"
      "net/http"
  )
  
  func main() {
      r, _ := http.NewRequest("GET", "http://example.com", nil)
      ctx, cancel := context.WithCancel(context.Background())
      r = r.WithContext(ctx)
      ch := make(chan bool)
      go func() {
          _, err := http.DefaultClient.Do(r)
          log.Println(err == context.Canceled)
          ch &lt;- true
      }()
      cancel()
      &lt;-ch
  }
  </code></pre>