hostMatches returns whether the host in u matches one of hosts.
(hosts []string, u *url.URL)
| 422 | |
| 423 | // hostMatches returns whether the host in u matches one of hosts. |
| 424 | func hostMatches(hosts []string, u *url.URL) bool { |
| 425 | for _, host := range hosts { |
| 426 | if u.Hostname() == host { |
| 427 | return true |
| 428 | } |
| 429 | if strings.HasPrefix(host, "*.") && strings.HasSuffix(u.Hostname(), host[2:]) { |
| 430 | return true |
| 431 | } |
| 432 | // Checks whether the host in u is an IP |
| 433 | if ip := net.ParseIP(u.Hostname()); ip != nil { |
| 434 | // Checks whether our current host is a CIDR |
| 435 | if _, ipnet, err := net.ParseCIDR(host); err == nil { |
| 436 | // Checks if our host contains the IP in u |
| 437 | if ipnet.Contains(ip) { |
| 438 | return true |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | return false |
| 445 | } |
| 446 | |
| 447 | // returns whether the referrer from the request is in the host list. |
| 448 | func referrerMatches(hosts []string, r *http.Request) bool { |
no outgoing calls