cancelreq_go14.go 467 B

1234567891011121314151617181920212223
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build !go1.5
  5. package ctxhttp
  6. import "net/http"
  7. type requestCanceler interface {
  8. CancelRequest(*http.Request)
  9. }
  10. func canceler(client *http.Client, req *http.Request) func() {
  11. rc, ok := client.Transport.(requestCanceler)
  12. if !ok {
  13. return func() {}
  14. }
  15. return func() {
  16. rc.CancelRequest(req)
  17. }
  18. }