-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: Add the ability to not follow redirects #278
Conversation
Currently, when we unmarshal, we get the default value, which is to follow redirects. Signed-off-by: Julien Pivotto <[email protected]>
Signed-off-by: Julien Pivotto <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few remarks.
Disclaimer: My HTTP foo is not strong enough to really say if this appropriately deals with the issues discussed in #5108.
config/http_config.go
Outdated
@@ -111,6 +111,10 @@ type HTTPClientConfig struct { | |||
ProxyURL URL `yaml:"proxy_url,omitempty"` | |||
// TLSConfig to use to connect to the targets. | |||
TLSConfig TLSConfig `yaml:"tls_config,omitempty"` | |||
// FollowRedirects specifies wheter the client should follow the HTTP 3xx redirects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wheter → whether
And I'd prefer "follow HTTP 3xx redirects" over "follow the HTTP 3xx rediracts".
config/http_config.go
Outdated
@@ -172,6 +176,9 @@ func (c *HTTPClientConfig) Validate() error { | |||
// UnmarshalYAML implements the yaml.Unmarshaler interface | |||
func (c *HTTPClientConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { | |||
type plain HTTPClientConfig | |||
*c = HTTPClientConfig{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overrides anything that might be pre-populated in *c
. Not sure if we ever do that, but wouldn't it be safer (and easier) to do c.FollowRedirects = true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No because C is nil at this point.
We do this in Prometheus:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have switched to the exact same pattern as prometheus (expose default struct)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FTR: If c
is nil
, then L179, as above, panics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmmmh yes indeed. but still, this is the pattern we use everywhere, let's stick to it?
Signed-off-by: Julien Pivotto <[email protected]>
3f9c8cc
to
f9eb271
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just silly comments and a typo left.
config/http_config.go
Outdated
@@ -111,6 +116,10 @@ type HTTPClientConfig struct { | |||
ProxyURL URL `yaml:"proxy_url,omitempty"` | |||
// TLSConfig to use to connect to the targets. | |||
TLSConfig TLSConfig `yaml:"tls_config,omitempty"` | |||
// FollowRedirects specifies wheter the client should follow HTTP 3xx redirects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still "wheter" → "whether"
config/http_config_test.go
Outdated
@@ -317,7 +357,7 @@ func TestNewClientFromConfig(t *testing.T) { | |||
} | |||
response, err := client.Get(testServer.URL) | |||
if err != nil { | |||
t.Errorf("Can't connect to the test server using this config: %+v", validConfig.clientConfig) | |||
t.Errorf("Can't connect to the test server using this config: %+v %v", validConfig.clientConfig, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's kind of hard to see that there is an error following after the config. How about:
"Can't connect to the test server using config %+v: %v"
@@ -172,6 +181,7 @@ func (c *HTTPClientConfig) Validate() error { | |||
// UnmarshalYAML implements the yaml.Unmarshaler interface | |||
func (c *HTTPClientConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { | |||
type plain HTTPClientConfig | |||
*c = DefaultHTTPClientConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said, this wouldn't work if c
were nil
. (Which implies that c
is not nil
rather than that we are doing anything wrong here.)
Signed-off-by: Julien Pivotto <[email protected]>
Thanks for your review, I think this is good to go. |
Yes, sure, that's why I had approved it already. (o: |
Currently, when we unmarshal, we get the default value, which is to
follow redirects.
Related to prometheus/prometheus#5108
Signed-off-by: Julien Pivotto [email protected]