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 client: Use Host field in URL if the Request Host is not present #888

Merged
merged 2 commits into from
Jun 15, 2024

Conversation

RonFed
Copy link
Contributor

@RonFed RonFed commented Jun 13, 2024

From the net/http documentation about the Request struct:

// For client requests, the URL's Host specifies the server to
// connect to, while the Request's Host field optionally
// specifies the Host header value to send in the HTTP
// request.
URL *url.URL

// For client requests, Host optionally overrides the Host
// header to send. If empty, the Request.Write method uses
// the value of URL.Host. Host may contain an international
// domain name.
Host string

Our current implementation can cause the host field to not be collected properly in some cases.
This can be reproduced using our e2e test by changing

resp, err := http.Get("http://user@localhost:8080/hello/42?query=true#fragment")

to

url, _ := url.Parse("http://user@localhost:8080/hello/42?query=true#fragment")
req := &http.Request{
  Method: http.MethodGet,
  URL:    url,
  }
req = req.WithContext(context.Background())
resp, err := http.DefaultClient.Do(req)

@RonFed RonFed marked this pull request as ready for review June 13, 2024 18:44
@RonFed RonFed requested a review from a team as a code owner June 13, 2024 18:44
Copy link
Contributor

@damemi damemi left a comment

Choose a reason for hiding this comment

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

Thanks @RonFed, I actually wasn't sure if there was a difference between the URL Host and Request Host in #790 so glad you looked into it!

@edeNFed edeNFed merged commit 22d9af3 into open-telemetry:main Jun 15, 2024
17 checks passed
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.

None yet

3 participants