Skip to content

Commit 275fbd4

Browse files
committed
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.
1 parent d790f7d commit 275fbd4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/getter/httpgetter.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020
"fmt"
2121
"io"
2222
"net/http"
23+
"strings"
2324

2425
"k8s.io/helm/pkg/tlsutil"
2526
"k8s.io/helm/pkg/urlutil"
27+
"k8s.io/helm/pkg/version"
2628
)
2729

2830
//httpGetter is the efault HTTP(/S) backend handler
@@ -34,7 +36,15 @@ type httpGetter struct {
3436
func (g *httpGetter) Get(href string) (*bytes.Buffer, error) {
3537
buf := bytes.NewBuffer(nil)
3638

37-
resp, err := g.client.Get(href)
39+
// Set a helm specific user agent so that a repo server and metrics can
40+
// separate helm calls from other tools interacting with repos.
41+
req, err := http.NewRequest("GET", href, nil)
42+
if err != nil {
43+
return buf, err
44+
}
45+
req.Header.Set("User-Agent", "Helm/"+strings.TrimPrefix(version.GetVersion(), "v"))
46+
47+
resp, err := g.client.Do(req)
3848
if err != nil {
3949
return buf, err
4050
}

0 commit comments

Comments
 (0)