mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
In Docker, subscription and RoutingA updates through the core dialled the default gateway instead of 127.0.0.1, a leftover from when the core ran outside v2rayA's container. The core now runs in v2rayA's own network namespace and, unless port sharing is on, listens on 127.0.0.1 only. With host networking the gateway is the LAN router, and on a bridge network the request only came back to the container when port sharing was on and the port was published, so updates in the "proxy" and "port rules" modes failed with connection refused. Fixes #2139
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package httpClient
|
|
|
|
import (
|
|
"github.com/v2rayA/v2rayA/db/configure"
|
|
"github.com/v2rayA/v2rayA/kernel/v2ray"
|
|
"net"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
// The core runs inside v2rayA's own process tree, in the same network
|
|
// namespace, and its proxy inbounds listen on 127.0.0.1 unless port sharing
|
|
// is on, so the loopback address reaches them in every environment,
|
|
// including Docker with bridge or host networking.
|
|
|
|
func GetHttpClientWithv2rayAProxy() (client *http.Client, err error) {
|
|
return GetHttpClientWithProxy("socks5://" + net.JoinHostPort("127.0.0.1", strconv.Itoa(configure.GetPortsNotNil().Socks5)))
|
|
}
|
|
|
|
func GetHttpClientWithv2rayAPac() (client *http.Client, err error) {
|
|
return GetHttpClientWithProxy("http://" + net.JoinHostPort("127.0.0.1", 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
|
|
}
|