MCPcopy
hub / github.com/helm/helm / get

Method get

pkg/getter/httpgetter.go:49–105  ·  view source on GitHub ↗
(href string, opts getterOptions)

Source from the content-addressed store, hash-verified

47}
48
49func (g *HTTPGetter) get(href string, opts getterOptions) (*bytes.Buffer, error) {
50 // Set a helm specific user agent so that a repo server and metrics can
51 // separate helm calls from other tools interacting with repos.
52 req, err := http.NewRequest(http.MethodGet, href, nil)
53 if err != nil {
54 return nil, err
55 }
56
57 if opts.acceptHeader != "" {
58 req.Header.Set("Accept", opts.acceptHeader)
59 }
60
61 req.Header.Set("User-Agent", version.GetUserAgent())
62 if opts.userAgent != "" {
63 req.Header.Set("User-Agent", opts.userAgent)
64 }
65
66 // Before setting the basic auth credentials, make sure the URL associated
67 // with the basic auth is the one being fetched.
68 u1, err := url.Parse(opts.url)
69 if err != nil {
70 return nil, fmt.Errorf("unable to parse getter URL: %w", err)
71 }
72 u2, err := url.Parse(href)
73 if err != nil {
74 return nil, fmt.Errorf("unable to parse URL getting from: %w", err)
75 }
76
77 // Host on URL (returned from url.Parse) contains the port if present.
78 // This check ensures credentials are not passed between different
79 // services on different ports.
80 if opts.passCredentialsAll || (u1.Scheme == u2.Scheme && u1.Host == u2.Host) {
81 if opts.username != "" && opts.password != "" {
82 req.SetBasicAuth(opts.username, opts.password)
83 }
84 }
85
86 client, err := g.httpClient(opts)
87 if err != nil {
88 return nil, err
89 }
90
91 slog.Debug("fetching", "url", href)
92 resp, err := client.Do(req)
93 if err != nil {
94 return nil, err
95 }
96 defer resp.Body.Close()
97 slog.Debug("fetch complete", "url", href, "status", resp.Status, "content-length", resp.ContentLength)
98 if resp.StatusCode != http.StatusOK {
99 return nil, fmt.Errorf("failed to fetch %s : %s", href, resp.Status)
100 }
101
102 buf := bytes.NewBuffer(nil)
103 _, err = io.Copy(buf, resp.Body)
104 return buf, err
105}
106

Callers 1

GetMethod · 0.95

Calls 6

httpClientMethod · 0.95
GetUserAgentFunction · 0.92
CloseMethod · 0.80
CopyMethod · 0.80
DoMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected