Skip to content
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

Merged
merged 4 commits into from
Feb 26, 2021

Conversation

roidelapluie
Copy link
Member

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]

Currently, when we unmarshal, we get the default value, which is to
follow redirects.

Signed-off-by: Julien Pivotto <[email protected]>
Copy link
Member

@beorn7 beorn7 left a 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.

@@ -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.
Copy link
Member

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".

@@ -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{
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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)

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

@beorn7 beorn7 left a 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.

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still "wheter" → "whether"

@@ -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)
Copy link
Member

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
Copy link
Member

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.)

Base automatically changed from master to main February 26, 2021 16:07
Signed-off-by: Julien Pivotto <[email protected]>
@roidelapluie
Copy link
Member Author

Thanks for your review, I think this is good to go.

@beorn7
Copy link
Member

beorn7 commented Feb 26, 2021

Yes, sure, that's why I had approved it already. (o:

@beorn7 beorn7 merged commit 47ee79a into prometheus:main Feb 26, 2021
This was referenced Mar 11, 2021
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants