-
-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added proxy support to the library, using ProxyURL parameter. (#256)
- Loading branch information
Showing
3 changed files
with
77 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"crypto/tls" | ||
"net" | ||
"net/http" | ||
"net/url" | ||
"time" | ||
|
||
"golang.org/x/time/rate" | ||
|
@@ -79,6 +80,10 @@ type Config struct { | |
|
||
EncryptionPolicy | ||
|
||
// Sets usage of Socks5 Proxy. Authentication should be included in the url if needed. | ||
// Example of setting: "socks5://demo:[email protected]:1080" | ||
ProxyURL string | ||
|
||
IPBlocklist iplist.Ranger | ||
DisableIPv6 bool `long:"disable-ipv6"` | ||
DisableIPv4 bool | ||
|
@@ -126,6 +131,9 @@ func (cfg *Config) SetListenAddr(addr string) *Config { | |
func (cfg *Config) setDefaults() { | ||
if cfg.HTTP == nil { | ||
cfg.HTTP = DefaultHTTPClient | ||
if cfg.ProxyURL != "" { | ||
cfg.setProxyURL() | ||
} | ||
} | ||
if cfg.HTTPUserAgent == "" { | ||
cfg.HTTPUserAgent = DefaultHTTPUserAgent | ||
|
@@ -166,6 +174,19 @@ func (cfg *Config) setDefaults() { | |
} | ||
} | ||
|
||
func (cfg *Config) setProxyURL() { | ||
fixedURL, err := url.Parse(cfg.ProxyURL) | ||
if err != nil { | ||
return | ||
} | ||
|
||
cfg.HTTP.Transport = &http.Transport{ | ||
Proxy: http.ProxyURL(fixedURL), | ||
TLSHandshakeTimeout: 15 * time.Second, | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
} | ||
} | ||
|
||
type EncryptionPolicy struct { | ||
DisableEncryption bool | ||
ForceEncryption bool // Don't allow unobfuscated connections. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters