AddFromString parses a string that contains comma-separated values specifying hosts that should use the bypass proxy. Each value is either an IP address, a CIDR range, a zone (*.example.com) or a host name (localhost). A best effort is made to parse the string and errors are ignored.
(s string)
| 98 | // (localhost). A best effort is made to parse the string and errors are |
| 99 | // ignored. |
| 100 | func (p *proxy_PerHost) AddFromString(s string) { |
| 101 | hosts := strings.Split(s, ",") |
| 102 | for _, host := range hosts { |
| 103 | host = strings.TrimSpace(host) |
| 104 | if len(host) == 0 { |
| 105 | continue |
| 106 | } |
| 107 | if strings.Contains(host, "/") { |
| 108 | // We assume that it's a CIDR address like 127.0.0.0/8 |
| 109 | if _, net, err := net.ParseCIDR(host); err == nil { |
| 110 | p.AddNetwork(net) |
| 111 | } |
| 112 | continue |
| 113 | } |
| 114 | if ip := net.ParseIP(host); ip != nil { |
| 115 | p.AddIP(ip) |
| 116 | continue |
| 117 | } |
| 118 | if strings.HasPrefix(host, "*.") { |
| 119 | p.AddZone(host[1:]) |
| 120 | continue |
| 121 | } |
| 122 | p.AddHost(host) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // AddIP specifies an IP address that will use the bypass proxy. Note that |
| 127 | // this will only take effect if a literal IP address is dialed. A connection |
no test coverage detected