mirror of
https://github.com/Jguer/yay.git
synced 2025-12-27 10:01:53 -05:00
socks5 support (#2543)
* socks5 support socks5 support via environment variable, e.g. SOCKS5_PROXY=localhost:1080 yay ... * use default transport and update tests to work on arm
This commit is contained in:
@@ -5,6 +5,7 @@ package runtime
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/Morganamilo/go-pacmanconf"
|
||||
@@ -21,13 +22,19 @@ func TestPacmanConf(t *testing.T) {
|
||||
absPath, err := filepath.Abs(path)
|
||||
require.NoError(t, err)
|
||||
|
||||
// detect the architecture of the system
|
||||
expectedArch := []string{"x86_64"}
|
||||
if runtime.GOARCH == "arm64" {
|
||||
expectedArch = []string{"aarch64"}
|
||||
}
|
||||
|
||||
expectedPacmanConf := &pacmanconf.Config{
|
||||
RootDir: "/", DBPath: "/var/lib/pacman/",
|
||||
CacheDir: []string{"/var/cache/pacman/pkg/"},
|
||||
HookDir: []string{"/etc/pacman.d/hooks/"},
|
||||
GPGDir: "/etc/pacman.d/gnupg/", LogFile: "/var/log/pacman.log",
|
||||
HoldPkg: []string{"pacman", "glibc"}, IgnorePkg: []string{"xorm"},
|
||||
IgnoreGroup: []string{"yorm"}, Architecture: []string{"x86_64"},
|
||||
IgnoreGroup: []string{"yorm"}, Architecture: expectedArch,
|
||||
XferCommand: "/usr/bin/wget --passive-ftp -c -O %o %u",
|
||||
NoUpgrade: []string(nil), NoExtract: []string(nil), CleanMethod: []string{"KeepInstalled"},
|
||||
SigLevel: []string{"PackageRequired", "PackageTrustedOnly", "DatabaseOptional", "DatabaseTrustedOnly"},
|
||||
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
"github.com/Jguer/aur/rpc"
|
||||
"github.com/Jguer/votar/pkg/vote"
|
||||
"github.com/Morganamilo/go-pacmanconf"
|
||||
|
||||
"golang.org/x/net/proxy"
|
||||
)
|
||||
|
||||
type Runtime struct {
|
||||
@@ -39,10 +41,20 @@ func NewRuntime(cfg *settings.Configuration, cmdArgs *parser.Arguments, version
|
||||
logger := text.NewLogger(os.Stdout, os.Stderr, os.Stdin, cfg.Debug, "runtime")
|
||||
runner := exe.NewOSRunner(logger.Child("runner"))
|
||||
|
||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
if socks5_proxy := os.Getenv("SOCKS5_PROXY"); socks5_proxy != "" {
|
||||
dialer, err := proxy.SOCKS5("tcp", socks5_proxy, nil, proxy.Direct)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
transport = &http.Transport{Dial: dialer.Dial}
|
||||
}
|
||||
|
||||
httpClient := &http.Client{
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
Transport: transport,
|
||||
}
|
||||
|
||||
userAgent := fmt.Sprintf("Yay/%s", version)
|
||||
|
||||
Reference in New Issue
Block a user