Files
Zakk 833af7dc74 refactor: use what the dependencies already provide
A read of the tree for home-grown code that a dependency or the platform
covers. Each item names what replaces it.

- IPv4 CIDR membership was a binary-string trie (infra/dataStructure/trie)
  fed with CIDRs rendered as bit strings; net.IPNet.Contains, which the
  same file already used for IPv6, does it. The trie package is gone.
- The response replay cache was an LRU with its own linked list, indexes
  and timeout strategy (infra/dataStructure/lru), of which one fixed-size
  instance existed; hashicorp/golang-lru/v2, already in go.mod, is that
  cache, typed. go mod tidy also dropped go-nanoid, which nothing imported.
- The HTTP client for subscription updates through the local proxy carried
  a CONNECT dialer of its own (pkg/util/proxyWithHttp); http.Transport's
  Proxy handles socks5:// and http:// URLs, resolves hostnames on the
  SOCKS proxy and uses CONNECT for https. Verified on the VM: a
  subscription update succeeds in both "pac" and "proxy" modes.
- core/dns/qtype.go listed nine type names in two switches before falling
  back to miekg/dns tables that contain the same names; dns.Type.String
  and dns.StringToType are the tables.
- The GUI tracked prefers-color-scheme with its own media query and
  toggled a theme-dark class nothing reads any more; Vuetify's "system"
  theme follows the OS itself. Verified in headless Chrome: auto follows
  the OS in both directions, an explicit choice overrides it.
- The AUR packages carried .INSTALL hooks whose only content was a
  coloured "Completed!" banner, duplicated in the deb/rpm after-install
  scripts; pacman and apt report that themselves. The hooks are gone, the
  release workflow stops copying them, and after_install/after_upgrade
  keep only daemon-reload and the restart.
- The tap release job downloaded eight artifacts in eight steps;
  actions/download-artifact takes a pattern with merge-multiple.
2026-09-20 16:40:34 +10:00

76 lines
2.1 KiB
Go

package httpClient
import (
"fmt"
"github.com/v2rayA/v2rayA/common"
"github.com/v2rayA/v2rayA/db/configure"
"github.com/v2rayA/v2rayA/kernel/v2ray"
"net"
"net/http"
"net/url"
"os/exec"
"strconv"
"strings"
)
func GetHttpClientWithProxy(proxyURL string) (client *http.Client, err error) {
u, err := url.Parse(proxyURL)
if err != nil {
return
}
return &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(u)}}, nil
}
func GetHttpClientWithv2rayAProxy() (client *http.Client, err error) {
host := "127.0.0.1"
//是否在docker环境
if common.IsDocker() {
//连接网关,即宿主机的端口
out, err := exec.Command("sh", "-c", "ip route list default|head -n 1|awk '{print $3}'").Output()
if err == nil {
host = strings.TrimSpace(string(out))
} else {
return nil, fmt.Errorf("failed to get gateway: %v", err)
}
}
return GetHttpClientWithProxy("socks5://" + net.JoinHostPort(host, strconv.Itoa(configure.GetPortsNotNil().Socks5)))
}
func GetHttpClientWithv2rayAPac() (client *http.Client, err error) {
host := "127.0.0.1"
//是否在docker环境
if common.IsDocker() {
//连接网关,即宿主机的端口
out, err := exec.Command("sh", "-c", "ip route|grep default|awk '{print $3}'").Output()
if err == nil {
host = strings.TrimSpace(string(out))
} else {
return nil, fmt.Errorf("failed to get gateway: %v", err)
}
}
return GetHttpClientWithProxy("http://" + net.JoinHostPort(host, strconv.Itoa(configure.GetPortsNotNil().HttpWithPac)))
}
func GetHttpClientAutomatically() (c *http.Client) {
setting := configure.GetSettingNotNil()
if !v2ray.ProcessManager.Running() || configure.GetConnectedServers() == nil || v2ray.IsTransparentOn(setting) {
return http.DefaultClient
}
var err error
switch setting.ProxyModeWhenSubscribe {
case configure.ProxyModePac:
c, err = GetHttpClientWithv2rayAPac()
if err != nil {
return http.DefaultClient
}
case configure.ProxyModeProxy:
c, err = GetHttpClientWithv2rayAProxy()
if err != nil {
return http.DefaultClient
}
default:
c = http.DefaultClient
}
return c
}