2016-09-09 03:44:25 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"errors"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
var errTLSConfigUnavailable = errors.New("TLSConfig unavailable")
|
|
|
|
|
|
|
|
// transportFunc allows us to inject a mock transport for testing. We define it
|
|
|
|
// here so we can detect the tlsconfig and return nil for only this type.
|
|
|
|
type transportFunc func(*http.Request) (*http.Response, error)
|
|
|
|
|
|
|
|
func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
|
|
return tf(req)
|
|
|
|
}
|
|
|
|
|
|
|
|
// resolveTLSConfig attempts to resolve the tls configuration from the
|
|
|
|
// RoundTripper.
|
2016-09-22 02:16:44 +00:00
|
|
|
func resolveTLSConfig(transport http.RoundTripper) *tls.Config {
|
2016-09-09 03:44:25 +00:00
|
|
|
switch tr := transport.(type) {
|
|
|
|
case *http.Transport:
|
2016-09-22 02:16:44 +00:00
|
|
|
return tr.TLSClientConfig
|
2016-09-09 03:44:25 +00:00
|
|
|
default:
|
2016-09-22 02:16:44 +00:00
|
|
|
return nil
|
2016-09-09 03:44:25 +00:00
|
|
|
}
|
|
|
|
}
|