| 1 | package lfshttpscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/ |
| 2 | |
| 3 | import ( |
| 4 | "net/httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/" |
| 5 | "net/urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/" |
| 6 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 7 | |
| 8 | "github.com/git-lfs/git-lfs/v3/configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/" |
| 9 | "golang.org/x/net/http/httpproxyscip-go gomod golang.org/x/net v0.57.0 `golang.org/x/net/http/httpproxy`/" |
| 10 | ) |
| 11 | |
| 12 | // Logic is copied, with small changes, from "net/http".ProxyFromEnvironment in the go std lib. |
| 13 | func proxyFromClientscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/proxyFromClient().(c *Clientscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Client#) func(req *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) (*urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#, error) { |
| 14 | return func(req *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) (*urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#, error) { |
| 15 | httpsProxy, httpProxy, noProxy := getProxyServersscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/getProxyServers().(req.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL., c.ucscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Client#uc., c.osEnvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Client#osEnv.) |
| 16 | |
| 17 | var proxy string |
| 18 | if req.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Schemescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Scheme. == "https" { |
| 19 | proxy = httpsProxy |
| 20 | } |
| 21 | |
| 22 | if len(proxy) == 0 { |
| 23 | proxy = httpProxy |
| 24 | } |
| 25 | |
| 26 | if len(proxy) == 0 { |
| 27 | return nil, nil |
| 28 | } |
| 29 | |
| 30 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(proxy, "socks5h://") { |
| 31 | proxy = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(proxy, "socks5h://", "socks5://", 1) |
| 32 | } |
| 33 | |
| 34 | cfg := &httpproxyscip-go gomod golang.org/x/net v0.57.0 `golang.org/x/net/http/httpproxy`/.Configscip-go gomod golang.org/x/net v0.57.0 `golang.org/x/net/http/httpproxy`/Config#{ |
| 35 | HTTPProxyscip-go gomod golang.org/x/net v0.57.0 `golang.org/x/net/http/httpproxy`/Config#HTTPProxy.: proxy, |
| 36 | HTTPSProxyscip-go gomod golang.org/x/net v0.57.0 `golang.org/x/net/http/httpproxy`/Config#HTTPSProxy.: proxy, |
| 37 | NoProxyscip-go gomod golang.org/x/net v0.57.0 `golang.org/x/net/http/httpproxy`/Config#NoProxy.: noProxy, |
| 38 | CGIscip-go gomod golang.org/x/net v0.57.0 `golang.org/x/net/http/httpproxy`/Config#CGI.: false, |
| 39 | } |
| 40 | |
| 41 | // We want to use the standard logic except that we want to |
| 42 | // allow proxies for localhost, which the standard library does |
| 43 | // not. Since the proxy code looks only at the URL, we |
| 44 | // synthesize a fake URL except that we rewrite "localhost" to |
| 45 | // "127.0.0.1" for purposes of looking up the proxy. |
| 46 | u := *(req.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL.) |
| 47 | if u.Hostscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Host. == "localhost" { |
| 48 | u.Hostscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Host. = "127.0.0.1" |
| 49 | } |
| 50 | return cfg.ProxyFuncscip-go gomod golang.org/x/net v0.57.0 `golang.org/x/net/http/httpproxy`/Config#ProxyFunc().()(&u) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func getProxyServersscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/getProxyServers().(u *urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#, urlCfg *configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.URLConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/URLConfig#, osEnv configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#) (httpsProxy string, httpProxy string, noProxy string) { |
| 55 | if osEnv == nil { |
| 56 | return |
| 57 | } |
| 58 | |
| 59 | if len(httpsProxy) == 0 { |
| 60 | httpsProxy, _ = osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("HTTPS_PROXY") |
| 61 | } |
| 62 | |
| 63 | if len(httpsProxy) == 0 { |
| 64 | httpsProxy, _ = osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("https_proxy") |
| 65 | } |
| 66 | |
| 67 | if len(httpProxy) == 0 { |
| 68 | httpProxy, _ = osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("HTTP_PROXY") |
| 69 | } |
| 70 | |
| 71 | if len(httpProxy) == 0 { |
| 72 | httpProxy, _ = osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("http_proxy") |
| 73 | } |
| 74 | |
| 75 | if urlCfg != nil { |
| 76 | gitProxy, ok := urlCfg.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/URLConfig#Get().("http", u.Stringscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#String().(), "proxy") |
| 77 | if len(gitProxy) > 0 && ok { |
| 78 | if u.Schemescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Scheme. == "https" { |
| 79 | httpsProxy = gitProxy |
| 80 | } |
| 81 | httpProxy = gitProxy |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | noProxy, _ = osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("NO_PROXY") |
| 86 | if len(noProxy) == 0 { |
| 87 | noProxy, _ = osEnv.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Get.("no_proxy") |
| 88 | } |
| 89 | |
| 90 | return |
| 91 | } |