mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
http client: remove dependency on global config options
This commit is contained in:
parent
065331c77f
commit
16b7b3bc3e
7 changed files with 148 additions and 72 deletions
|
@ -41,7 +41,7 @@ func (h *Handler) CreateFeed(userID, categoryID int64, url string, crawler bool,
|
|||
return nil, errors.NewLocalizedError(errCategoryNotFound)
|
||||
}
|
||||
|
||||
request := client.New(url)
|
||||
request := client.NewClientWithConfig(url, config.Opts)
|
||||
request.WithCredentials(username, password)
|
||||
request.WithUserAgent(userAgent)
|
||||
|
||||
|
@ -108,7 +108,7 @@ func (h *Handler) RefreshFeed(userID, feedID int64) error {
|
|||
originalFeed.CheckedNow()
|
||||
originalFeed.ScheduleNextCheck(weeklyEntryCount)
|
||||
|
||||
request := client.New(originalFeed.FeedURL)
|
||||
request := client.NewClientWithConfig(originalFeed.FeedURL, config.Opts)
|
||||
request.WithCredentials(originalFeed.Username, originalFeed.Password)
|
||||
request.WithUserAgent(originalFeed.UserAgent)
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/crypto"
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/logger"
|
||||
|
@ -23,7 +24,7 @@ import (
|
|||
// FindIcon try to find the website's icon.
|
||||
func FindIcon(websiteURL string, fetchViaProxy bool) (*model.Icon, error) {
|
||||
rootURL := url.RootURL(websiteURL)
|
||||
clt := client.New(rootURL)
|
||||
clt := client.NewClientWithConfig(rootURL, config.Opts)
|
||||
if fetchViaProxy {
|
||||
clt.WithProxy()
|
||||
}
|
||||
|
@ -90,7 +91,7 @@ func parseDocument(websiteURL string, data io.Reader) (string, error) {
|
|||
}
|
||||
|
||||
func downloadIcon(iconURL string, fetchViaProxy bool) (*model.Icon, error) {
|
||||
clt := client.New(iconURL)
|
||||
clt := client.NewClientWithConfig(iconURL, config.Opts)
|
||||
if fetchViaProxy {
|
||||
clt.WithProxy()
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"io"
|
||||
"strings"
|
||||
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/logger"
|
||||
"miniflux.app/reader/readability"
|
||||
|
@ -20,7 +21,7 @@ import (
|
|||
|
||||
// Fetch downloads a web page and returns relevant contents.
|
||||
func Fetch(websiteURL, rules, userAgent string) (string, error) {
|
||||
clt := client.New(websiteURL)
|
||||
clt := client.NewClientWithConfig(websiteURL, config.Opts)
|
||||
if userAgent != "" {
|
||||
clt.WithUserAgent(userAgent)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/errors"
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/reader/browser"
|
||||
|
@ -30,15 +31,15 @@ func FindSubscriptions(websiteURL, userAgent, username, password string, fetchVi
|
|||
websiteURL = findYoutubeChannelFeed(websiteURL)
|
||||
websiteURL = parseYoutubeVideoPage(websiteURL)
|
||||
|
||||
request := client.New(websiteURL)
|
||||
request.WithCredentials(username, password)
|
||||
request.WithUserAgent(userAgent)
|
||||
clt := client.NewClientWithConfig(websiteURL, config.Opts)
|
||||
clt.WithCredentials(username, password)
|
||||
clt.WithUserAgent(userAgent)
|
||||
|
||||
if fetchViaProxy {
|
||||
request.WithProxy()
|
||||
clt.WithProxy()
|
||||
}
|
||||
|
||||
response, err := browser.Exec(request)
|
||||
response, err := browser.Exec(clt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -118,8 +119,8 @@ func parseYoutubeVideoPage(websiteURL string) string {
|
|||
return websiteURL
|
||||
}
|
||||
|
||||
request := client.New(websiteURL)
|
||||
response, browserErr := browser.Exec(request)
|
||||
clt := client.NewClientWithConfig(websiteURL, config.Opts)
|
||||
response, browserErr := browser.Exec(clt)
|
||||
if browserErr != nil {
|
||||
return websiteURL
|
||||
}
|
||||
|
@ -155,10 +156,10 @@ func tryWellKnownUrls(websiteURL, userAgent, username, password string) (Subscri
|
|||
if err != nil {
|
||||
continue
|
||||
}
|
||||
request := client.New(fullURL)
|
||||
request.WithCredentials(username, password)
|
||||
request.WithUserAgent(userAgent)
|
||||
response, err := request.Get()
|
||||
clt := client.NewClientWithConfig(fullURL, config.Opts)
|
||||
clt.WithCredentials(username, password)
|
||||
clt.WithUserAgent(userAgent)
|
||||
response, err := clt.Get()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue