mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Add HTTP proxy option for subscriptions
This commit is contained in:
parent
0f258fd55b
commit
cf7712acea
40 changed files with 201 additions and 65 deletions
|
@ -47,6 +47,7 @@ type Client struct {
|
|||
password string
|
||||
userAgent string
|
||||
Insecure bool
|
||||
fetchViaProxy bool
|
||||
}
|
||||
|
||||
func (c *Client) String() string {
|
||||
|
@ -93,6 +94,12 @@ func (c *Client) WithCacheHeaders(etagHeader, lastModifiedHeader string) *Client
|
|||
return c
|
||||
}
|
||||
|
||||
// WithProxy enable proxy for current HTTP client request.
|
||||
func (c *Client) WithProxy() *Client {
|
||||
c.fetchViaProxy = true
|
||||
return c
|
||||
}
|
||||
|
||||
// WithUserAgent defines the User-Agent header to use for outgoing requests.
|
||||
func (c *Client) WithUserAgent(userAgent string) *Client {
|
||||
if userAgent != "" {
|
||||
|
@ -230,12 +237,23 @@ func (c *Client) buildRequest(method string, body io.Reader) (*http.Request, err
|
|||
|
||||
func (c *Client) buildClient() http.Client {
|
||||
client := http.Client{Timeout: time.Duration(config.Opts.HTTPClientTimeout()) * time.Second}
|
||||
transport := &http.Transport{}
|
||||
if c.Insecure {
|
||||
client.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
||||
if c.fetchViaProxy && config.Opts.HasHTTPClientProxyConfigured() {
|
||||
proxyURL, err := url.Parse(config.Opts.HTTPClientProxy())
|
||||
if err != nil {
|
||||
logger.Error("[HttpClient] Proxy URL error: %v", err)
|
||||
} else {
|
||||
logger.Debug("[HttpClient] Use proxy: %s", proxyURL)
|
||||
transport.Proxy = http.ProxyURL(proxyURL)
|
||||
}
|
||||
}
|
||||
|
||||
client.Transport = transport
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue