diff --git a/.chloggen/cookie_support.yaml b/.chloggen/cookie_support.yaml index 040c5f00c60..d360efa6177 100644 --- a/.chloggen/cookie_support.yaml +++ b/.chloggen/cookie_support.yaml @@ -7,7 +7,7 @@ change_type: enhancement component: confighttp # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Add support for cookies in HTTP clients with `cookies_enabled`. +note: Add support for cookies in HTTP clients with `cookies::enabled`. # One or more tracking issues or pull requests related to the change issues: [10175] diff --git a/config/confighttp/README.md b/config/confighttp/README.md index 991360fe8c7..897919a3388 100644 --- a/config/confighttp/README.md +++ b/config/confighttp/README.md @@ -34,7 +34,8 @@ README](../configtls/README.md). - [`disable_keep_alives`](https://golang.org/pkg/net/http/#Transport) - [`http2_read_idle_timeout`](https://pkg.go.dev/golang.org/x/net/http2#Transport) - [`http2_ping_timeout`](https://pkg.go.dev/golang.org/x/net/http2#Transport) -- [`cookies_enabled`](https://pkg.go.dev/net/http#CookieJar) if enabled, the client will store cookies from server responses and reuse them in subsequent requests. +- [`cookies`](https://pkg.go.dev/net/http#CookieJar) + - [`enabled`] if enabled, the client will store cookies from server responses and reuse them in subsequent requests. Example: @@ -52,6 +53,8 @@ exporter: test1: "value1" "test 2": "value 2" compression: zstd + cookies: + enabled: true ``` ## Server Configuration diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 343a8cf6f81..f31b4920ef0 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -100,10 +100,14 @@ type ClientConfig struct { // HTTP2PingTimeout if there's no response to the ping within the configured value, the connection will be closed. // If not set or set to 0, it defaults to 15s. HTTP2PingTimeout time.Duration `mapstructure:"http2_ping_timeout"` + // Cookies configures the cookie management of the HTTP client. + Cookies *CookiesConfig `mapstructure:"cookies"` +} - // CookiesEnabled enables reusing cookies between requests. - // This is useful to manage sticky session cookies. - CookiesEnabled bool `mapstructure:"cookies_enabled"` +// CookiesConfig defines the configuration of the HTTP client regarding cookies served by the server. +type CookiesConfig struct { + // Enabled if true, cookies from HTTP responses will be reused in further HTTP requests with the same server. + Enabled bool `mapstructure:"enabled"` } // NewDefaultClientConfig returns ClientConfig type object with @@ -233,7 +237,7 @@ func (hcs *ClientConfig) ToClient(ctx context.Context, host component.Host, sett } var jar http.CookieJar - if hcs.CookiesEnabled { + if hcs.Cookies != nil && hcs.Cookies.Enabled { jar, err = cookiejar.New(nil) if err != nil { return nil, err diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 32b55f77355..a53d2fc977e 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -82,7 +82,7 @@ func TestAllHTTPClientSettings(t *testing.T) { CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) { return next, nil }, Compression: "", DisableKeepAlives: true, - CookiesEnabled: true, + Cookies: &CookiesConfig{Enabled: true}, HTTP2ReadIdleTimeout: idleConnTimeout, HTTP2PingTimeout: http2PingTimeout, },