cancelreq.go 475 B

123456789101112131415161718192021
  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.go
  5. // +build go1.5
  6. // Package httputil provides HTTP utility functions.
  7. package httputil
  8. import "net/http"
  9. func RequestCanceler(rt http.RoundTripper, req *http.Request) func() {
  10. ch := make(chan struct{})
  11. req.Cancel = ch
  12. return func() {
  13. close(ch)
  14. }
  15. }