xfy 2734b04d8f refactor: remove 16.8k lines of dead code across all internal packages
- Delete unused files: tempfile subsystem, matcher variants, server/internal
- Remove 200+ unused functions across proxy, ssl, lua, http2/3, stream, variable
- Fix proxy test type errors (backgroundRefresh ctx→Request)
- Move bench/tools mock backend into internal/testutil
- Remove corresponding test functions for all deleted code
2026-06-03 16:15:43 +08:00

49 lines
952 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package netutil 提供网络相关的工具函数。
//
// 该文件包含主机名处理相关的工具函数。
//
// 作者xfy
package netutil
// StripPort 从 Host 头中移除端口号。
//
// 支持 IPv4 和 IPv6 格式:
// - example.com:8080 -> example.com
// - [::1]:8080 -> [::1]
// - [2001:db8::1]:443 -> [2001:db8::1]
// - example.com -> example.com
//
// 参数:
// - host: 主机名(可能包含端口)
//
// 返回值:
// - string: 移除端口后的主机名
func StripPort(host string) string {
if len(host) == 0 {
return host
}
// IPv6 格式:以 '[' 开头,找 ']:' 作为分隔点
if host[0] == '[' {
for i := 0; i < len(host)-1; i++ {
if host[i] == ']' && host[i+1] == ':' {
return host[:i+1]
}
}
return host
}
// IPv4 或域名格式:找第一个 ':' 作为分隔点
for i := 0; i < len(host); i++ {
if host[i] == ':' {
return host[:i]
}
}
return host
}