From 275fbd431c09b42f6dc232e5e826fbd881a7148b Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Mon, 20 Nov 2017 13:05:03 -0500 Subject: [PATCH] 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. --- pkg/getter/httpgetter.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/getter/httpgetter.go b/pkg/getter/httpgetter.go index 9afa31f60..5a2146ec6 100644 --- a/pkg/getter/httpgetter.go +++ b/pkg/getter/httpgetter.go @@ -20,9 +20,11 @@ import ( "fmt" "io" "net/http" + "strings" "k8s.io/helm/pkg/tlsutil" "k8s.io/helm/pkg/urlutil" + "k8s.io/helm/pkg/version" ) //httpGetter is the efault HTTP(/S) backend handler @@ -34,7 +36,15 @@ type httpGetter struct { func (g *httpGetter) Get(href string) (*bytes.Buffer, error) { 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 { return buf, err }