mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-28 04:10:44 -04:00
do not panic when Client.Transport is not *http.Transport (#3440)
This commit is contained in:
parent
6775fe4927
commit
022e93f627
2 changed files with 23 additions and 3 deletions
|
|
@ -271,9 +271,10 @@ func NewClient(c *Config) (*Client, error) {
|
|||
c.HttpClient.Transport = cleanhttp.DefaultTransport()
|
||||
}
|
||||
|
||||
tp := c.HttpClient.Transport.(*http.Transport)
|
||||
if err := http2.ConfigureTransport(tp); err != nil {
|
||||
return nil, err
|
||||
if tp, ok := c.HttpClient.Transport.(*http.Transport); ok {
|
||||
if err := http2.ConfigureTransport(tp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
redirFunc := func() {
|
||||
|
|
|
|||
|
|
@ -194,3 +194,22 @@ func TestClientTimeoutSetting(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
type roundTripperFunc func(*http.Request) (*http.Response, error)
|
||||
|
||||
func (rt roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
return rt(r)
|
||||
}
|
||||
|
||||
func TestClientNonTransportRoundTripper(t *testing.T) {
|
||||
client := &http.Client{
|
||||
Transport: roundTripperFunc(http.DefaultTransport.RoundTrip),
|
||||
}
|
||||
|
||||
_, err := NewClient(&Config{
|
||||
HttpClient: client,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue