mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	Use proxy for pull mirror (#22771)
- Use the proxy (if one is specified) for pull mirrors syncs.
- Pulled the code from
c2774d9e80/modules/git/repo.go (L164-L170)
Downstream issue: https://codeberg.org/forgejo/forgejo/issues/302
---------
Co-authored-by: Lauris BH <lauris@nix.lv>
			
			
This commit is contained in:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user