aboutsummaryrefslogtreecommitdiffhomepage
path: root/caddyconfig/httpcaddyfile/addresses.go
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2021-10-20 10:27:59 -0600
committerMatthew Holt <[email protected]>2021-10-20 10:27:59 -0600
commit0ffb2229b00c3e6b484fb7fac6d5ff8d652c2cc8 (patch)
treee6535ca2693faa37d929b150f551e2bb06c0f12d /caddyconfig/httpcaddyfile/addresses.go
parenta21d5a001fbbe0764b748d6ae4c83a9a54cbd7b0 (diff)
downloadcaddy-0ffb2229b00c3e6b484fb7fac6d5ff8d652c2cc8.tar.gz
caddy-0ffb2229b00c3e6b484fb7fac6d5ff8d652c2cc8.zip
httpcaddyfile: Preserve IPv6 addresses through normalization (fix #4381)
Remove unnecessary Key() method and improve related tests
Diffstat (limited to 'caddyconfig/httpcaddyfile/addresses.go')
-rw-r--r--caddyconfig/httpcaddyfile/addresses.go26
1 files changed, 3 insertions, 23 deletions
diff --git a/caddyconfig/httpcaddyfile/addresses.go b/caddyconfig/httpcaddyfile/addresses.go
index 710532047..a4f07ae60 100644
--- a/caddyconfig/httpcaddyfile/addresses.go
+++ b/caddyconfig/httpcaddyfile/addresses.go
@@ -337,7 +337,9 @@ func (a Address) Normalize() Address {
// ensure host is normalized if it's an IP address
host := strings.TrimSpace(a.Host)
if ip := net.ParseIP(host); ip != nil {
- host = ip.String()
+ if ipv6 := ip.To16(); ipv6 != nil && ipv6.DefaultMask() == nil {
+ host = ipv6.String()
+ }
}
return Address{
@@ -349,28 +351,6 @@ func (a Address) Normalize() Address {
}
}
-// Key returns a string form of a, much like String() does, but this
-// method doesn't add anything default that wasn't in the original.
-func (a Address) Key() string {
- res := ""
- if a.Scheme != "" {
- res += a.Scheme + "://"
- }
- if a.Host != "" {
- res += a.Host
- }
- // insert port only if the original has its own explicit port
- if a.Port != "" &&
- len(a.Original) >= len(res) &&
- strings.HasPrefix(a.Original[len(res):], ":"+a.Port) {
- res += ":" + a.Port
- }
- if a.Path != "" {
- res += a.Path
- }
- return res
-}
-
// lowerExceptPlaceholders lowercases s except within
// placeholders (substrings in non-escaped '{ }' spans).
// See https://github.com/caddyserver/caddy/issues/3264