(parsed *url.URL)
| 208 | } |
| 209 | |
| 210 | func webFetchProxyURLForRequest(parsed *url.URL) *url.URL { |
| 211 | if parsed == nil { |
| 212 | return nil |
| 213 | } |
| 214 | |
| 215 | host := strings.TrimSpace(strings.ToLower(parsed.Hostname())) |
| 216 | if host == "" { |
| 217 | return nil |
| 218 | } |
| 219 | if host == "localhost" || strings.HasSuffix(host, ".localhost") || isPrivateOrLocalHostname(host) { |
| 220 | return nil |
| 221 | } |
| 222 | if noProxyMatches(host) { |
| 223 | return nil |
| 224 | } |
| 225 | |
| 226 | scheme := strings.ToLower(strings.TrimSpace(parsed.Scheme)) |
| 227 | candidates := []string{} |
| 228 | if scheme == "https" { |
| 229 | candidates = append(candidates, os.Getenv("HTTPS_PROXY"), os.Getenv("https_proxy")) |
| 230 | } |
| 231 | candidates = append(candidates, os.Getenv("HTTP_PROXY"), os.Getenv("http_proxy")) |
| 232 | |
| 233 | for _, raw := range candidates { |
| 234 | raw = strings.TrimSpace(raw) |
| 235 | if raw == "" { |
| 236 | continue |
| 237 | } |
| 238 | proxyURL, err := url.Parse(raw) |
| 239 | if err != nil || proxyURL == nil { |
| 240 | continue |
| 241 | } |
| 242 | return proxyURL |
| 243 | } |
| 244 | return nil |
| 245 | } |
| 246 | |
| 247 | func webFetchProxyEnabledForURL(parsed *url.URL) bool { |
| 248 | return webFetchProxyURLForRequest(parsed) != nil |
no test coverage detected