feat(getter): add optional session header for HTTP requests

- Introduce helm-session header to group requests per Helm command
- Make behavior optional via WithSessionHeader option
- Keep default behavior unchanged to avoid side effects
- Add unit test to verify consistent session ID across requests

Signed-off-by: Vaishnav Sreekumar <vaishnavsreekumar301@gmail.com>
Signed-off-by: vaish123-fullstck <vaishnavsreekumar301@gmail.com>
pull/31967/head
vaish123-fullstck 7 months ago
parent d68d505afa
commit e55d2ce201

@ -49,6 +49,7 @@ type getterOptions struct {
timeout time.Duration timeout time.Duration
transport *http.Transport transport *http.Transport
artifactType string artifactType string
sessionHeader bool
} }
// Option allows specifying various settings configurable by the user for overriding the defaults // Option allows specifying various settings configurable by the user for overriding the defaults
@ -106,6 +107,11 @@ func WithTLSClientConfig(certFile, keyFile, caFile string) Option {
opts.caFile = caFile opts.caFile = caFile
} }
} }
func WithSessionHeader(enabled bool) Option {
return func(opts *getterOptions) {
opts.sessionHeader = enabled
}
}
func WithPlainHTTP(plainHTTP bool) Option { func WithPlainHTTP(plainHTTP bool) Option {
return func(opts *getterOptions) { return func(opts *getterOptions) {

@ -1,18 +1,3 @@
/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package getter package getter
import ( import (
@ -30,7 +15,6 @@ import (
"helm.sh/helm/v4/internal/version" "helm.sh/helm/v4/internal/version"
) )
// Add constant (minimal addition)
const helmSessionHeader = "helm-session" const helmSessionHeader = "helm-session"
// HTTPGetter is the default HTTP(/S) backend handler // HTTPGetter is the default HTTP(/S) backend handler
@ -38,8 +22,6 @@ type HTTPGetter struct {
opts getterOptions opts getterOptions
transport *http.Transport transport *http.Transport
once sync.Once once sync.Once
// Add session field (minimal addition)
sessionID string sessionID string
} }
@ -58,8 +40,8 @@ func (g *HTTPGetter) get(href string, opts getterOptions) (*bytes.Buffer, error)
return nil, err return nil, err
} }
// Set helm session header for traceability // ✅ Optional session header (correct implementation)
if g.sessionID != "" { if g.sessionID != "" && opts.sessionHeader {
req.Header.Set(helmSessionHeader, g.sessionID) req.Header.Set(helmSessionHeader, g.sessionID)
} }
@ -115,7 +97,6 @@ func NewHTTPGetter(options ...Option) (Getter, error) {
opt(&client.opts) opt(&client.opts)
} }
// Generate session ID (minimal addition)
client.sessionID = uuid.New().String() client.sessionID = uuid.New().String()
return &client, nil return &client, nil

@ -689,7 +689,7 @@ func TestHTTPGetterSessionHeader(t *testing.T) {
defer srv.Close() defer srv.Close()
// Create getter for HTTP session header test // Create getter for HTTP session header test
g, err := NewHTTPGetter(WithURL(srv.URL)) g, err := NewHTTPGetter(WithURL(srv.URL), WithSessionHeader(true))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

Loading…
Cancel
Save