Revert "Revert "Treat URLs have same IP address as same""
This reverts commit 3153e635d5
.
Conflicts:
etcdserver/config.go
This commit is contained in:
@ -19,6 +19,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/pkg/capnslog"
|
||||
@ -60,6 +61,51 @@ func ResolveTCPAddrs(urls ...[]url.URL) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// URLsEqual checks equality of url.URLS between two arrays.
|
||||
// This check pass even if an URL is in hostname and opposite is in IP address.
|
||||
func URLsEqual(a []url.URL, b []url.URL) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i, urlA := range a {
|
||||
urlB := b[i]
|
||||
|
||||
if !reflect.DeepEqual(urlA, urlB) {
|
||||
urls := []url.URL{urlA, urlB}
|
||||
ResolveTCPAddrs(urls)
|
||||
if !reflect.DeepEqual(urls[0], urls[1]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func URLStringsEqual(a []string, b []string) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
urlsA := make([]url.URL, len(a))
|
||||
for _, str := range a {
|
||||
u, err := url.Parse(str)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
urlsA = append(urlsA, *u)
|
||||
}
|
||||
urlsB := make([]url.URL, len(b))
|
||||
for _, str := range b {
|
||||
u, err := url.Parse(str)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
urlsB = append(urlsB, *u)
|
||||
}
|
||||
|
||||
return URLsEqual(urlsA, urlsB)
|
||||
}
|
||||
|
||||
// BasicAuth returns the username and password provided in the request's
|
||||
// Authorization header, if the request uses HTTP Basic Authentication.
|
||||
// See RFC 2617, Section 2.
|
||||
|
Reference in New Issue
Block a user