Skip to content

middleware: handle Host routing via Request.Host#1118

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

middleware: handle Host routing via Request.Host#1118
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

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

Copy link
Copy Markdown
Contributor Author

Friendly follow-up: this patch keeps the API surface unchanged, but makes Host-based routing line up with how net/http actually exposes host information (Request.Host instead of Request.Header["Host"]).

It also adds host-with-port coverage, which seems useful for local development cases like example.com:8080.

@happysnaker

Copy link
Copy Markdown
Contributor Author

Resubmitted from a restored public fork as #1120. Closing this thread in favor of the new PR so the contribution stays reviewable from a proper fork relationship.

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