Skip to content

fix: IPv6-safe virtual host port stripping via net.SplitHostPort#2206

Closed
Copilot wants to merge 2 commits intodev-vhostfrom
copilot/sub-pr-2202-another-one
Closed

fix: IPv6-safe virtual host port stripping via net.SplitHostPort#2206
Copilot wants to merge 2 commits intodev-vhostfrom
copilot/sub-pr-2202-another-one

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

Both stripDownHostPort (down.go) and stripPort (virtual_host.go) failed to strip ports from bracketed IPv6 hosts — [::1]:5244 was returned unchanged, causing all IPv6 vhost lookups to miss.

Changes

  • server/middlewares/helpers.go (new): Shared stripHostPort helper using net.SplitHostPort, which handles IPv4, bracketed IPv6, and port-free hosts correctly
  • down.go: Remove stripDownHostPort; use stripHostPort
  • virtual_host.go: Remove stripPort and unused strings import; use stripHostPort
// Before — [::1]:5244 returns unchanged (bracket detected, port not stripped)
func stripPort(host string) string {
    if idx := strings.LastIndex(host, ":"); idx != -1 {
        if !strings.Contains(host, "[") {
            return host[:idx]
        }
    }
    return host
}

// After — delegates to net.SplitHostPort; [::1]:5244 → ::1
func stripHostPort(host string) string {
    h, _, err := net.SplitHostPort(host)
    if err != nil {
        return host
    }
    return h
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: PIKACHUIM <40362270+PIKACHUIM@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback from PR #2202 on virtual host support fix: IPv6-safe virtual host port stripping via net.SplitHostPort Mar 9, 2026
@jyxjjj jyxjjj closed this Mar 9, 2026
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.

3 participants