MCPcopy Index your code
hub / github.com/coder/coder / normalizeHost

Function normalizeHost

coderd/httpmw/apikey.go:780–811  ·  view source on GitHub ↗

normalizeHost performs host normalization including case-insensitive conversion and IDN (Internationalized Domain Name) punnycode normalization.

(host string)

Source from the content-addressed store, hash-verified

778// normalizeHost performs host normalization including case-insensitive conversion
779// and IDN (Internationalized Domain Name) punnycode normalization.
780func normalizeHost(host string) string {
781 if host == "" {
782 return host
783 }
784
785 // Handle IPv6 addresses - they are enclosed in brackets
786 if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
787 // IPv6 addresses should be normalized to lowercase
788 return strings.ToLower(host)
789 }
790
791 // Extract port if present
792 var port string
793 if idx := strings.LastIndex(host, ":"); idx > 0 {
794 // Check if this is actually a port (not part of IPv6)
795 if !strings.Contains(host[idx+1:], ":") {
796 port = host[idx:]
797 host = host[:idx]
798 }
799 }
800
801 // Convert to lowercase for case-insensitive comparison
802 host = strings.ToLower(host)
803
804 // Apply IDN normalization - convert Unicode domain names to ASCII (punnycode)
805 if normalizedHost, err := idna.ToASCII(host); err == nil {
806 host = normalizedHost
807 }
808 // If IDN conversion fails, continue with lowercase version
809
810 return host + port
811}
812
813// normalizePathSegments normalizes path segments for consistent OAuth2 audience matching.
814// Uses url.URL.ResolveReference() which implements RFC 3986 dot-segment removal.

Callers 2

normalizeAudienceURIFunction · 0.70
TestNormalizeHostFunction · 0.70

Calls 1

ContainsMethod · 0.45

Tested by 1

TestNormalizeHostFunction · 0.56