Skip to content

Conversation

@alxfv
Copy link

@alxfv alxfv commented Nov 26, 2025

Description

This PR ensures that the HTTP Host header is correctly set to match the target ClickHouse server's host when proxying requests. Previously, the Host header could retain the original proxy address, which could cause issues with host routing or server-side host validation.

According to the HTTP specification:

MDN - Host Header

The HTTP Host request header specifies the host and port number of the server to which the request is being sent. A Host header field must be sent in all HTTP/1.1 request messages.

RFC 9110 Section 7.2

The "Host" header field in a request provides the host and port information from the target URI, enabling the origin server to distinguish among resources while servicing requests for multiple host names.

The target URI's authority information is critical for handling a request. A user agent MUST generate a Host header field in a request unless it sends that information as an ":authority" pseudo-header field.

Real-world impact:

The incorrect Host header can cause issues in environments using host routing, such as AWS Application Load Balancers with host-based routing rules, where requests are routed based on the Host header value.

Example scenario from issue #415:

Before

Request to chproxy:
  Host: localhost:8124
  URL: http://localhost:8124/?query=SELECT 1

Proxied to ClickHouse:
  Host: localhost:8124  (incorrect - kept original)
  URL: https://backend.example.com:8123/?query=SELECT 1

After

Request to chproxy:
  Host: localhost:8124
  URL: http://localhost:8124/?query=SELECT 1

Proxied to ClickHouse:
  Host: backend.example.com:8123 (correct - matches backend)
  URL: https://backend.example.com:8123/?query=SELECT 1

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Checklist

  • Linter passes correctly
  • Add tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary

Does this introduce a breaking change?

  • Yes
  • No

Further comments

Fixes: #415

Signed-off-by: Alexander Fedorov <afedorov26@bloomberg.net>
@alxfv alxfv changed the title Set Host header to match target host in proxied requests [BUG] Set Host header to match target host in proxied requests Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant