From 9e4087f2eff874cd69823fe36bc0dfd383d8557a Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Mon, 25 Oct 2021 15:39:47 +0800 Subject: [PATCH] fix: http proxy auth --- service/pkg/util/proxyWithHttp/proxyWithHttp.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/service/pkg/util/proxyWithHttp/proxyWithHttp.go b/service/pkg/util/proxyWithHttp/proxyWithHttp.go index 86e075e4..a22957ff 100644 --- a/service/pkg/util/proxyWithHttp/proxyWithHttp.go +++ b/service/pkg/util/proxyWithHttp/proxyWithHttp.go @@ -44,6 +44,10 @@ type httpProxy struct { forward proxy.Dialer } +func newHTTPSProxy(uri *url.URL, forward proxy.Dialer) (proxy.Dialer, error) { + return newHTTPProxy(uri, HttpsDialer) +} + func newHTTPProxy(uri *url.URL, forward proxy.Dialer) (proxy.Dialer, error) { s := new(httpProxy) s.host = uri.Host @@ -80,8 +84,10 @@ func (s *httpProxy) Dial(network, addr string) (net.Conn, error) { req.Close = false if s.haveAuth { req.SetBasicAuth(s.username, s.password) + req.Header.Set("Proxy-Authorization", req.Header.Get("Authorization")) + req.Header.Del("Authorization") } - req.Header.Set("User-Agent", "Powerby Gota") + req.Header.Set("User-Agent", "v2rayA") err = req.Write(c) if err != nil { @@ -117,5 +123,5 @@ func FromEnvironment() proxy.Dialer { func init() { proxy.RegisterDialerType("http", newHTTPProxy) - proxy.RegisterDialerType("https", newHTTPProxy) + proxy.RegisterDialerType("https", newHTTPSProxy) }