feat(http): Add a Helm user-agent string to the http getter

Adding a user-agent to the http getter will enable servers to
distinguish between helm (including various versions) and other
tools connecting to the server.
pull/3174/head
Matt Farina 7 years ago
parent d790f7d843
commit 275fbd431c
No known key found for this signature in database
GPG Key ID: CDBDE65D3E544BF3

@ -20,9 +20,11 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"strings"
"k8s.io/helm/pkg/tlsutil" "k8s.io/helm/pkg/tlsutil"
"k8s.io/helm/pkg/urlutil" "k8s.io/helm/pkg/urlutil"
"k8s.io/helm/pkg/version"
) )
//httpGetter is the efault HTTP(/S) backend handler //httpGetter is the efault HTTP(/S) backend handler
@ -34,7 +36,15 @@ type httpGetter struct {
func (g *httpGetter) Get(href string) (*bytes.Buffer, error) { func (g *httpGetter) Get(href string) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
resp, err := g.client.Get(href) // Set a helm specific user agent so that a repo server and metrics can
// separate helm calls from other tools interacting with repos.
req, err := http.NewRequest("GET", href, nil)
if err != nil {
return buf, err
}
req.Header.Set("User-Agent", "Helm/"+strings.TrimPrefix(version.GetVersion(), "v"))
resp, err := g.client.Do(req)
if err != nil { if err != nil {
return buf, err return buf, err
} }

Loading…
Cancel
Save