Skip to content

middleware: handle Host routing via Request.Host#1120

Open
happysnaker wants to merge 1 commit into
go-chi:masterfrom
happysnaker:fix-routeheaders-host
Open

middleware: handle Host routing via Request.Host#1120
happysnaker wants to merge 1 commit into
go-chi:masterfrom
happysnaker:fix-routeheaders-host

Conversation

@happysnaker

Copy link
Copy Markdown
Contributor

Summary

  • read Request.Host for RouteHeaders rules targeting Host
  • document the net/http host promotion behavior in the middleware docs
  • add coverage for host matching with and without an explicit port

Why

net/http promotes the HTTP Host header to Request.Host and removes it from Request.Header, so the existing Host-based example in RouteHeaders is misleading for normal browser traffic. This patch makes Host routing behave the way users expect and updates the docs/tests accordingly.

Closes #691

Note

This PR supersedes #1118, which I had to close after the original fork relationship was broken during repo visibility changes on my side. The code/content is the same contribution path, now resubmitted from a proper public fork.

Signed-off-by: happysnaker <73147033+happysnaker@users.noreply.github.com>
@happysnaker

Copy link
Copy Markdown
Contributor Author

Maintainer note: this patch intentionally targets the existing documented Host use case in RouteHeaders and keeps the change minimal by reading Request.Host, which is where Go promotes the HTTP Host header for normal server requests. Tests cover host matching with and without a port so behavior stays explicit.

@happysnaker

Copy link
Copy Markdown
Contributor Author

Keeping this warm: the intent of this patch is still to make the documented RouteHeaders(...).Route("Host", ...) usage work with normal Go server requests by reading Request.Host, including the common host:port case. Tests cover exact-host and wildcard-host matching with and without a port, and the change stays local to middleware/route_headers.go.

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.

Subdomain example in route_headers.go not working

1 participant