cancelreq.go 458 B

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