// Roundtrip is a single connection simplistic HTTP client
// that allows us to bypass a connection pool to test load balancing
// used in tests, as it only supports GET request on /
554960
func Roundtrip(addr string) (string, error) {
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		return "", err
	}
	defer conn.Close()
	return RoundtripWithConn(conn)
}
1234107
func (a *agentForwarder) RoundTrip(r *http.Request) (*http.Response, error) {
	r.Header.Add("User-Agent", a.agent)
	return a.Transport.RoundTrip(r)
}
1168691
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
	_, span := trace.StartSpan(req.Context(), "elastic:PerformRequest")
	attrs := append([]trace.Attribute(nil), t.defaultAttributes...)
	attrs = append(attrs,
		trace.StringAttribute("Component", "github.com/olivere/elastic/v7"),
		trace.StringAttribute("Method", req.Method),
		trace.StringAttribute("URL", req.URL.String()),
		trace.StringAttribute("Hostname", req.URL.Hostname()),
		trace.Int64Attribute("Port", atoi64(req.URL.Port())),
	)
	span.AddAttributes(attrs...)

	var (
		resp *http.Response
		err  error
	)
	defer func() {
		setSpanStatus(span, err)
		span.End()
	}()
	if t.rt != nil {
		resp, err = t.rt.RoundTrip(req)
	} else {
		resp, err = http.DefaultTransport.RoundTrip(req)
	}
	return resp, err
}
756666
func (t *xrayTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	s := ContextSegment(req.Context())
	if s == nil {
		return t.wrapped.RoundTrip(req)
	}

	sub := s.NewSubsegment(req.URL.Host)
	defer sub.Close()

	sub.RecordRequest(req, "remote")

	resp, err := t.wrapped.RoundTrip(req)

	if err != nil {
		sub.RecordError(err)
	} else {
		sub.RecordResponse(resp)
	}

	return resp, err
}
1001335
func (t *CookieAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	if t.SessionObject == nil {
		err := t.setSessionObject()
		if err != nil {
			return nil, errors.Wrap(err, "cookieauth: no session object has been set")
		}
	}

	req2 := cloneRequest(req) // per RoundTripper contract
	for _, cookie := range t.SessionObject {
		// Don't add an empty value cookie to the request
		if cookie.Value != "" {
			req2.AddCookie(cookie)
		}
	}

	return t.transport().RoundTrip(req2)
}
814191
func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	// To set extra headers, we must make a copy of the Request so
	// that we don't modify the Request we were given. This is required by the
	// specification of http.RoundTripper.
	//
	// Since we are going to modify only req.Header here, we only need a deep copy
	// of req.Header.
	req2 := new(http.Request)
	*req2 = *req
	req2.Header = make(http.Header, len(req.Header))
	for k, s := range req.Header {
		req2.Header[k] = append([]string(nil), s...)
	}

	req2.SetBasicAuth(t.Username, t.Password)
	if t.OTP != "" {
		req2.Header.Set(headerOTP, t.OTP)
	}
	return t.transport().RoundTrip(req2)
}
941650
func RoundtripWithConn(conn net.Conn) (string, error) {
	_, err := fmt.Fprintf(conn, "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n")
	if err != nil {
		return "", err
	}

	re, err := http.ReadResponse(bufio.NewReader(conn), nil)
	if err != nil {
		return "", err
	}
	defer re.Body.Close()
	out, err := ioutil.ReadAll(re.Body)
	if err != nil {
		return "", err
	}
	return string(out), nil
}
1245501
func (rt RoundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
	return rt(r)
}
106366
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
	ctx := context.WithValue(req.Context(), ContextKeyRequestStart, time.Now())
	req = req.WithContext(ctx)

	t.logRequest(req)

	resp, err := t.transport().RoundTrip(req)
	if err != nil {
		return resp, err
	}

	t.logResponse(resp)

	return resp, err
}
901793
func (limiters *RateLimiters) RoundTripper(rt http.RoundTripper, host string) http.RoundTripper {
	limiters.mu.Lock()
	defer limiters.mu.Unlock()

	if limiters.perHost == nil {
		limiters.perHost = map[string]*rate.Limiter{}
	}
	if _, ok := limiters.perHost[host]; !ok {
		rl := rate.NewLimiter(rate.Limit(limiters.RPS), limiters.Burst)
		limiters.perHost[host] = rl
	}
	var reduceOnce sync.Once
	return &RoundTripRateLimiter{
		rl: limiters.perHost[host],
		tx: rt,
		slowDown: func() {
			reduceOnce.Do(func() { limiters.BackOff(host) })
		},
	}
}
983178
func contextTransport(ctx context.Context) http.RoundTripper {
	if client, ok := ctx.Value(HTTPClient).(*http.Client); ok {
		return client.Transport
	}
	return nil
}
1152325
func (a *Authenticator) Transport() (http.RoundTripper, error) {
	switch useAuth, err := a.doLoginIfRequired(false); {
	case err != nil:
		return nil, err
	case useAuth:
		return a.transport, nil // token-injecting transport
	default:
		return a.opts.Transport, nil // original non-authenticating transport
	}
}
1233819
func (it *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
	statusCode := BogusStatusCode

	// Remember the current time.
	now := time.Now()

	// Make the request using the next RoundTripper.
	resp, err := it.next.RoundTrip(req)
	if resp != nil {
		statusCode = resp.StatusCode
	}

	// Observe the time it took to make the request.
	RequestDurationSeconds.WithLabelValues(
		req.URL.Scheme,
		req.URL.Host,
		it.cbs.PathProcessor(req.URL.Path),
		it.cbs.QueryProcessor(req.URL.RawQuery),
		req.Method,
		it.cbs.CodeProcessor(statusCode),
	).Observe(time.Since(now).Seconds())

	// return the response and error reported from the next RoundTripper.
	return resp, err
}
814538
func RoundTripperFor(config *restclient.Config) (http.RoundTripper, Upgrader, error) {
	tlsConfig, err := restclient.TLSConfigFor(config)
	if err != nil {
		return nil, nil, err
	}
	upgradeRoundTripper := spdy.NewRoundTripper(tlsConfig, true, false)
	wrapper, err := restclient.HTTPWrappersForConfig(config, upgradeRoundTripper)
	if err != nil {
		return nil, nil, err
	}
	return wrapper, upgradeRoundTripper, nil
}
144157
func (t *tlsRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	b, h, err := t.getCAWithHash()
	if err != nil {
		return nil, err
	}

	t.mtx.RLock()
	equal := bytes.Equal(h[:], t.hashCAFile)
	rt := t.rt
	t.mtx.RUnlock()
	if equal {
		// The CA cert hasn't changed, use the existing RoundTripper.
		return rt.RoundTrip(req)
	}

	// Create a new RoundTripper.
	tlsConfig := t.tlsConfig.Clone()
	if !updateRootCA(tlsConfig, b) {
		return nil, fmt.Errorf("unable to use specified CA cert %s", t.caFile)
	}
	rt, err = t.newRT(tlsConfig)
	if err != nil {
		return nil, err
	}
	t.CloseIdleConnections()

	t.mtx.Lock()
	t.rt = rt
	t.hashCAFile = h[:]
	t.mtx.Unlock()

	return rt.RoundTrip(req)
}
917404
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
	if t.source == nil {
		return nil, fmt.Errorf("oauth1: Transport's source is nil")
	}
	accessToken, err := t.source.Token()
	if err != nil {
		return nil, err
	}
	if t.auther == nil {
		return nil, fmt.Errorf("oauth1: Transport's auther is nil")
	}
	// RoundTripper should not modify the given request, clone it
	req2 := cloneRequest(req)
	err = t.auther.setRequestAuthHeader(req2, accessToken)
	if err != nil {
		return nil, err
	}
	return t.base().RoundTrip(req2)
}
437551
func NewTransport(clientOptionFuncs ...OptionTransportFunc) (http.RoundTripper, error) {
	t := dcosTransport{}
	for _, opt := range clientOptionFuncs {
		if err := opt(&t); err != nil {
			return nil, err
		}
	}

	tr, err := configureTLS(t.CaCertificatePath)
	if err != nil {
		return nil, err
	}

	if len(t.IAMConfigPath) != 0 {
		withIAM, err := NewRoundTripper(
			tr,
			OptionReadIAMConfig(t.IAMConfigPath))
		if err != nil {
			return nil, err
		}
		return withIAM, nil
	}

	return tr, nil
}