func (s *snapshotSender) post(req *http.Request) (err error) {
	ctx, cancel := context.WithCancel(context.Background())
	req = req.WithContext(ctx)
	defer cancel()

	type responseAndError struct {
		resp *http.Response
		body []byte
		err  error
	}
	result := make(chan responseAndError, 1)

	go func() {
		resp, err := s.tr.pipelineRt.RoundTrip(req)
		if err != nil {
			result <- responseAndError{resp, nil, err}
			return
		}

		// close the response body when timeouts.
		// prevents from reading the body forever when the other side dies right after
		// successfully receives the request body.
		time.AfterFunc(snapResponseReadTimeout, func() { httputil.GracefulClose(resp) })
		body, err := ioutil.ReadAll(resp.Body)
		result <- responseAndError{resp, body, err}
	}()

	select {
	case <-s.stopc:
		return errStopped
	case r := <-result:
		if r.err != nil {
			return r.err
		}
		return checkPostResponse(r.resp, r.body, req, s.to)
	}
}
func (s *snapshotSender) post(req *http.Request) (err error) {
	ctx, cancel := context.WithCancel(context.Background())
	req = req.WithContext(ctx)
	defer cancel()

	type responseAndError struct {
		resp *http.Response
		body []byte
		err  error
	}
	result := make(chan responseAndError, 1)

	go func() {
		resp, err := s.tr.pipelineRt.RoundTrip(req)
		if err != nil {
			result <- responseAndError{resp, nil, err}
			return
		}

		
		
		
		time.AfterFunc(snapResponseReadTimeout, func() { httputil.GracefulClose(resp) })
		body, err := ioutil.ReadAll(resp.Body)
		result <- responseAndError{resp, body, err}
	}()

	select {
	case <-s.stopc:
		return errStopped
	case r := <-result:
		if r.err != nil {
			return r.err
		}
		return checkPostResponse(r.resp, r.body, req, s.to)
	}
}
func ( s * snapshotSender ) post ( req * http . Request ) ( err error ) { ctx , cancel := context . WithCancel ( context . Background ( ) ) req = req . WithContext ( ctx ) defer cancel ( ) type responseAndError struct { resp * http . Response body [ ] byte err error } result := make ( chan responseAndError , 1 ) go func ( ) { resp , err := s . tr . pipelineRt . RoundTrip ( req ) if err != nil { result <- responseAndError { resp , nil , err } return } // close the response body when timeouts. // prevents from reading the body forever when the other side dies right after // successfully receives the request body. time . AfterFunc ( snapResponseReadTimeout , func ( ) { httputil . GracefulClose ( resp ) } ) body , err := ioutil . ReadAll ( resp . Body ) result <- responseAndError { resp , body , err } } ( ) select { case <- s . stopc : return errStopped case r := <- result : if r . err != nil { return r . err } return checkPostResponse ( r . resp , r . body , req , s . to ) } }
// post posts the given request.
// It returns nil when request is sent out and processed successfully.
post posts the given request . It returns nil when request is sent out and processed successfully .