aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/git/repo.go6
-rw-r--r--modules/proxy/proxy.go14
2 files changed, 16 insertions, 4 deletions
diff --git a/modules/git/repo.go b/modules/git/repo.go
index e77a3a6ad8..233f7f20cf 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -163,10 +163,8 @@ func CloneWithArgs(ctx context.Context, args TrustedCmdArgs, from, to string, op
envs := os.Environ()
u, err := url.Parse(from)
- if err == nil && (strings.EqualFold(u.Scheme, "http") || strings.EqualFold(u.Scheme, "https")) {
- if proxy.Match(u.Host) {
- envs = append(envs, fmt.Sprintf("https_proxy=%s", proxy.GetProxyURL()))
- }
+ if err == nil {
+ envs = proxy.EnvWithProxy(u)
}
stderr := new(bytes.Buffer)
diff --git a/modules/proxy/proxy.go b/modules/proxy/proxy.go
index f0cd366c12..1a6bdad7fb 100644
--- a/modules/proxy/proxy.go
+++ b/modules/proxy/proxy.go
@@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"os"
+ "strings"
"sync"
"code.gitea.io/gitea/modules/log"
@@ -82,3 +83,16 @@ func Proxy() func(req *http.Request) (*url.URL, error) {
return http.ProxyFromEnvironment(req)
}
}
+
+// EnvWithProxy returns os.Environ(), with a https_proxy env, if the given url
+// needs to be proxied.
+func EnvWithProxy(u *url.URL) []string {
+ envs := os.Environ()
+ if strings.EqualFold(u.Scheme, "http") || strings.EqualFold(u.Scheme, "https") {
+ if Match(u.Host) {
+ envs = append(envs, "https_proxy="+GetProxyURL())
+ }
+ }
+
+ return envs
+}