cache http client in http registry

This commit is contained in:
Yann Hamon 2020-11-08 16:50:21 +01:00
parent 9d7a79b253
commit 44710f9053

View file

@ -9,7 +9,7 @@ import (
) )
type KubernetesRegistry struct { type KubernetesRegistry struct {
http *http.Transport c *http.Client
schemaPathTemplate string schemaPathTemplate string
strict bool strict bool
} }
@ -29,12 +29,13 @@ func newHTTPRegistry(schemaPathTemplate string, strict bool, skipTLS bool) *Kube
IdleConnTimeout: 3 * time.Second, IdleConnTimeout: 3 * time.Second,
DisableCompression: true, DisableCompression: true,
} }
if skipTLS { if skipTLS {
reghttp.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} reghttp.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
} }
return &KubernetesRegistry{ return &KubernetesRegistry{
http: reghttp, c: &http.Client{Transport: reghttp},
schemaPathTemplate: schemaPathTemplate, schemaPathTemplate: schemaPathTemplate,
strict: strict, strict: strict,
} }
@ -46,8 +47,7 @@ func (r KubernetesRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8s
return nil, err return nil, err
} }
client := &http.Client{Transport: r.http} resp, err := r.c.Get(url)
resp, err := client.Get(url)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed downloading schema at %s: %s", url, err) return nil, fmt.Errorf("failed downloading schema at %s: %s", url, err)
} }