cancelreq_go14.go 527 B

12345678910111213141516171819202122232425
  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. // borrowed from golang/net/context/ctxhttp/cancelreq_go14.go
  5. // +build !go1.5
  6. package httputil
  7. import "net/http"
  8. type requestCanceler interface {
  9. CancelRequest(req *http.Request)
  10. }
  11. func RequestCanceler(rt http.RoundTripper, req *http.Request) func() {
  12. c, ok := rt.(requestCanceler)
  13. if !ok {
  14. return func() {}
  15. }
  16. return func() {
  17. c.CancelRequest(req)
  18. }
  19. }