Skip to content

Commit 8da559f

Browse files
authored
[confighttp] Use configoptional.Optional for CookiesConfig (#14154)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description <!-- Issue number if applicable --> Uses `configoptional.Optional` for `confighttp.ClientConfig.Cookies` field. This should be transparent for end users iff they have the `configoptional.AddEnabledField` feature gate enabled (the default) #### Link to tracking issue Updates #14021
1 parent 5adc149 commit 8da559f

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: pkg/config/confighttp
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Use configoptional.Optional for confighttp.ClientConfig.Cookies field
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [14021]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: []

config/confighttp/client.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type ClientConfig struct {
101101
// If not set or set to 0, it defaults to 15s.
102102
HTTP2PingTimeout time.Duration `mapstructure:"http2_ping_timeout,omitempty"`
103103
// Cookies configures the cookie management of the HTTP client.
104-
Cookies CookiesConfig `mapstructure:"cookies,omitempty"`
104+
Cookies configoptional.Optional[CookiesConfig] `mapstructure:"cookies,omitempty"`
105105

106106
// Enabling ForceAttemptHTTP2 forces the HTTP transport to use the HTTP/2 protocol.
107107
// By default, this is set to true.
@@ -116,9 +116,7 @@ type ClientConfig struct {
116116

117117
// CookiesConfig defines the configuration of the HTTP client regarding cookies served by the server.
118118
type CookiesConfig struct {
119-
// Enabled if true, cookies from HTTP responses will be reused in further HTTP requests with the same server.
120-
Enabled bool `mapstructure:"enabled,omitempty"`
121-
_ struct{}
119+
_ struct{}
122120
}
123121

124122
// NewDefaultClientConfig returns ClientConfig type object with
@@ -265,7 +263,7 @@ func (cc *ClientConfig) ToClient(ctx context.Context, host component.Host, setti
265263
}
266264

267265
var jar http.CookieJar
268-
if cc.Cookies.Enabled {
266+
if cc.Cookies.HasValue() {
269267
jar, err = cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
270268
if err != nil {
271269
return nil, err

config/confighttp/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestAllHTTPClientSettings(t *testing.T) {
7575
IdleConnTimeout: idleConnTimeout,
7676
Compression: "",
7777
DisableKeepAlives: true,
78-
Cookies: CookiesConfig{Enabled: true},
78+
Cookies: configoptional.Some(CookiesConfig{}),
7979
HTTP2ReadIdleTimeout: idleConnTimeout,
8080
HTTP2PingTimeout: http2PingTimeout,
8181
},
@@ -97,7 +97,7 @@ func TestAllHTTPClientSettings(t *testing.T) {
9797
IdleConnTimeout: idleConnTimeout,
9898
Compression: "",
9999
DisableKeepAlives: true,
100-
Cookies: CookiesConfig{Enabled: true},
100+
Cookies: configoptional.Some(CookiesConfig{}),
101101
HTTP2ReadIdleTimeout: idleConnTimeout,
102102
HTTP2PingTimeout: http2PingTimeout,
103103
},

0 commit comments

Comments
 (0)