transport.go 712 B

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