Merge pull request #6173 from gyuho/ccc

pkg/httputil: simplify RequestCanceler args
This commit is contained in:
Xiang Li 2016-08-14 20:41:19 -07:00 committed by GitHub
commit 96e018634a
5 changed files with 5 additions and 5 deletions

View File

@ -13,7 +13,7 @@ import (
"net/http" "net/http"
) )
func RequestCanceler(rt http.RoundTripper, req *http.Request) func() { func RequestCanceler(req *http.Request) func() {
ch := make(chan struct{}) ch := make(chan struct{})
req.Cancel = ch req.Cancel = ch

View File

@ -110,7 +110,7 @@ func (p *reverseProxy) ServeHTTP(rw http.ResponseWriter, clientreq *http.Request
var requestClosed int32 var requestClosed int32
completeCh := make(chan bool, 1) completeCh := make(chan bool, 1)
closeNotifier, ok := rw.(http.CloseNotifier) closeNotifier, ok := rw.(http.CloseNotifier)
cancel := httputil.RequestCanceler(p.transport, proxyreq) cancel := httputil.RequestCanceler(proxyreq)
if ok { if ok {
closeCh := closeNotifier.CloseNotify() closeCh := closeNotifier.CloseNotify()
go func() { go func() {

View File

@ -117,7 +117,7 @@ func (p *pipeline) post(data []byte) (err error) {
req := createPostRequest(u, RaftPrefix, bytes.NewBuffer(data), "application/protobuf", p.tr.URLs, p.tr.ID, p.tr.ClusterID) req := createPostRequest(u, RaftPrefix, bytes.NewBuffer(data), "application/protobuf", p.tr.URLs, p.tr.ID, p.tr.ClusterID)
done := make(chan struct{}, 1) done := make(chan struct{}, 1)
cancel := httputil.RequestCanceler(p.tr.pipelineRt, req) cancel := httputil.RequestCanceler(req)
go func() { go func() {
select { select {
case <-done: case <-done:

View File

@ -103,7 +103,7 @@ func (s *snapshotSender) send(merged snap.Message) {
// post posts the given request. // post posts the given request.
// It returns nil when request is sent out and processed successfully. // It returns nil when request is sent out and processed successfully.
func (s *snapshotSender) post(req *http.Request) (err error) { func (s *snapshotSender) post(req *http.Request) (err error) {
cancel := httputil.RequestCanceler(s.tr.pipelineRt, req) cancel := httputil.RequestCanceler(req)
type responseAndError struct { type responseAndError struct {
resp *http.Response resp *http.Response

View File

@ -413,7 +413,7 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) {
return nil, fmt.Errorf("stream reader is stopped") return nil, fmt.Errorf("stream reader is stopped")
default: default:
} }
cr.cancel = httputil.RequestCanceler(cr.tr.streamRt, req) cr.cancel = httputil.RequestCanceler(req)
cr.mu.Unlock() cr.mu.Unlock()
resp, err := cr.tr.streamRt.RoundTrip(req) resp, err := cr.tr.streamRt.RoundTrip(req)