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

Update the Host field in the request header #854

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HaoweiCh
Copy link

@HaoweiCh HaoweiCh commented Oct 8, 2023

This update checks for the 'Host' value in the request header, specifically assigning it to 'u.Host' if no value is found. This same logic is applied to 'cfg.ServerName'. The aim of this change is to ensure a correct 'Host' value is used throughout, addressing a bug related to setting the 'Host' field of the header.

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Go Version Update
  • Dependency Update

Description

Related Tickets & Documents

  • Related Issue #
  • Closes #

Added/updated tests?

  • Yes
  • No, and this is why: please replace this line with details on why tests
    have not been included
  • I need help with writing tests

Run verifications and test

  • make verify is passing
  • make test is passing

This update checks for the 'Host' value in the request header, specifically assigning it to 'u.Host' if no value is found. This same logic is applied to 'cfg.ServerName'. The aim of this change is to ensure a correct 'Host' value is used throughout, addressing a bug related to setting the 'Host' field of the header.
@HaoweiCh
Copy link
Author

HaoweiCh commented Oct 9, 2023

When it comes to dealing with dynamic servers that the application controls, the ability to send data through a Content Delivery Network (CDN) is a big deal for me. It becomes especially important when I have to forward WebSocket connections. This feature allows me to use DNS over HTTPS (DoH) to look up and specifically choose the server's IP address. Particularly with Cloudflare CDN, I can even customize and select specific IP addresses for Cloudflare's edge nodes. To put it simply, this gives me the flexibility and control I need to ensure smooth communication between the application and the server.

@ghost
Copy link

ghost commented Oct 10, 2023

Is this a correct statement of the problem: specify the sever address separate from the host used in the request header and when negotiating TLS.

If the statement of the problem is correct, then use the net dial function:

 addr := "example1.com:80" // server address
 url := "wss://example2.com/ws"  // use example2.com in host header and for TLS

 wsd := websocket.Dialer{
     NetDialContext: func(ctx context.Context, network, urlAddr string) (net.Conn, error) {
          // urlAddr is the address taken from the request
         // URL. We ignore that address when dialing the 
         // underlying network connection.
         var nd net.Dialer        
         return nd.DialContext(ctx, network, addr)
    },
}
ws, _, err := wsd.DialContext(ctx, url, nil)

@HaoweiCh
Copy link
Author

curl 1.2.3.4 -H "Host: example.com".
to be honestly, I think the custom header setting should has higher priority, same logic like curl command.
and I think this should be inside framework. :)

@ghost
Copy link

ghost commented Oct 10, 2023

This package should follow the design of the net/http package, not curl. The net/http package ignores the application specified Host header (start here to view the code).

This package solves your underlying problem using the net dial function. Whether the package should add additional ways to solve the problem is up to the package maintainers.

If the maintainers do decide to proceed forward with this PR, then the PR should be updated to include:

  • Documentation for the new feature.
  • A test for the new feature.
  • A PR comment analyzing what happens to existing applications that set the Host header. Does this PR break those applications, or were the applications flawed to begin with?

I am not asking you to do any of the items above. That's up to the maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

1 participant