Source File
proxy.go
Belonging Package
vendor/golang.org/x/net/http/httpproxy
package httpproxy
import (
)
func () *Config {
return &Config{
HTTPProxy: getEnvAny("HTTP_PROXY", "http_proxy"),
HTTPSProxy: getEnvAny("HTTPS_PROXY", "https_proxy"),
NoProxy: getEnvAny("NO_PROXY", "no_proxy"),
CGI: os.Getenv("REQUEST_METHOD") != "",
}
}
func ( ...string) string {
for , := range {
if := os.Getenv(); != "" {
return
}
}
return ""
}
:= &config{
Config: *,
}
.init()
return .proxyForURL
}
func ( *config) ( *url.URL) (*url.URL, error) {
var *url.URL
if .Scheme == "https" {
= .httpsProxy
} else if .Scheme == "http" {
= .httpProxy
if != nil && .CGI {
return nil, errors.New("refusing to use HTTP_PROXY value in CGI environment; see golang.org/s/cgihttpproxy")
}
}
if == nil {
return nil, nil
}
if !.useProxy(canonicalAddr()) {
return nil, nil
}
return , nil
}
func ( string) (*url.URL, error) {
if == "" {
return nil, nil
}
, := url.Parse()
if != nil ||
(.Scheme != "http" &&
.Scheme != "https" &&
func ( *config) ( string) bool {
if len() == 0 {
return true
}
, , := net.SplitHostPort()
if != nil {
return false
}
if == "localhost" {
return false
}
:= net.ParseIP()
if != nil {
if .IsLoopback() {
return false
}
}
= strings.ToLower(strings.TrimSpace())
if != nil {
for , := range .ipMatchers {
if .match(, , ) {
return false
}
}
}
for , := range .domainMatchers {
if .match(, , ) {
return false
}
}
return true
}
func ( *config) () {
if , := parseProxy(.HTTPProxy); == nil {
.httpProxy =
}
if , := parseProxy(.HTTPSProxy); == nil {
.httpsProxy =
}
for , := range strings.Split(.NoProxy, ",") {
= strings.ToLower(strings.TrimSpace())
if len() == 0 {
continue
}
if == "*" {
.ipMatchers = []matcher{allMatch{}}
.domainMatchers = []matcher{allMatch{}}
return
}
if , , := net.ParseCIDR(); == nil {
.ipMatchers = append(.ipMatchers, cidrMatch{cidr: })
continue
}
, , := net.SplitHostPort()
if == nil {
if := net.ParseIP(); != nil {
.ipMatchers = append(.ipMatchers, ipMatch{ip: , port: })
continue
}
continue
}
if strings.HasPrefix(, "*.") {
= [1:]
}
:= false
if [0] != '.' {
= true
= "." +
}
.domainMatchers = append(.domainMatchers, domainMatch{host: , port: , matchHost: })
}
}
var portMap = map[string]string{
"http": "80",
"https": "443",
"socks5": "1080",
}
type allMatch struct{}
func ( allMatch) (, string, net.IP) bool {
return true
}
type cidrMatch struct {
cidr *net.IPNet
}
func ( cidrMatch) (, string, net.IP) bool {
return .cidr.Contains()
}
type ipMatch struct {
ip net.IP
port string
}
func ( ipMatch) (, string, net.IP) bool {
if .ip.Equal() {
return .port == "" || .port ==
}
return false
}
type domainMatch struct {
host string
port string
matchHost bool
}
func ( domainMatch) (, string, net.IP) bool {
if strings.HasSuffix(, .host) || (.matchHost && == .host[1:]) {
return .port == "" || .port ==
}
return false
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |