-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathgetproxy_common.go
50 lines (40 loc) · 1.35 KB
/
getproxy_common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//go:build darwin || windows || linux
package main
import (
"github.com/bdwyertech/go-get-proxied/proxy"
"net/http"
"net/url"
)
var getproxy_httpProxyURL *url.URL
var getproxy_httpsProxyURL *url.URL
func GetProxy(r *http.Request) (*url.URL, error) {
if r == nil && getproxy_httpProxyURL == nil && getproxy_httpsProxyURL == nil {
proxyProvider := proxy.NewProvider("")
httpProxy := proxyProvider.GetHTTPProxy("")
if httpProxy != nil {
getproxy_httpProxyURL = httpProxy.URL()
if getproxy_httpProxyURL.Scheme == "" {
getproxy_httpProxyURL.Scheme = "http"
}
Log("GetProxy", GetLangText("GetProxy_ProxyFound"), true, "HTTP", getproxy_httpProxyURL.String(), httpProxy.Src())
}
httpsProxy := proxyProvider.GetHTTPSProxy("")
if httpsProxy != nil {
getproxy_httpsProxyURL = httpsProxy.URL()
if getproxy_httpsProxyURL.Scheme == "" {
getproxy_httpsProxyURL.Scheme = "http"
}
Log("GetProxy", GetLangText("GetProxy_ProxyFound"), true, "HTTPS", getproxy_httpsProxyURL.String(), httpsProxy.Src())
}
if getproxy_httpProxyURL == nil || getproxy_httpsProxyURL == nil {
Log("GetProxy", GetLangText("GetProxy_ProxyNotFound"), true, "HTTP/HTTPS")
}
} else if r != nil {
if r.URL.Scheme == "https" {
return getproxy_httpsProxyURL, nil
} else if r.URL.Scheme == "http" {
return getproxy_httpProxyURL, nil
}
}
return nil, nil
}