transport.go 635 B

12345678910111213141516171819202122232425
  1. package client
  2. import (
  3. "crypto/tls"
  4. "net/http"
  5. )
  6. // transportFunc allows us to inject a mock transport for testing. We define it
  7. // here so we can detect the tlsconfig and return nil for only this type.
  8. type transportFunc func(*http.Request) (*http.Response, error)
  9. func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) {
  10. return tf(req)
  11. }
  12. // resolveTLSConfig attempts to resolve the TLS configuration from the
  13. // RoundTripper.
  14. func resolveTLSConfig(transport http.RoundTripper) *tls.Config {
  15. switch tr := transport.(type) {
  16. case *http.Transport:
  17. return tr.TLSClientConfig
  18. default:
  19. return nil
  20. }
  21. }