aboutsummaryrefslogtreecommitdiffhomepage
path: root/http
diff options
context:
space:
mode:
authorGravatar Patrick <pmarschik@users.noreply.github.com>2018-09-20 03:19:24 +0200
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-09-19 18:19:24 -0700
commit2538eea1776e1d03d33465ad2001512caca93937 (patch)
tree021c417d5f31606fe50d7945872c4cda6cdc2060 /http
parent1d335390c2ac7c0feeb94fce89eefdae9a1e7c17 (diff)
Add the possibility to override default user agent for each feed
Diffstat (limited to 'http')
-rw-r--r--http/client/client.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/http/client/client.go b/http/client/client.go
index 201b136..2dce15c 100644
--- a/http/client/client.go
+++ b/http/client/client.go
@@ -33,6 +33,9 @@ const (
)
var (
+ // DefaultUserAgent sets the User-Agent header used for any requests by miniflux.
+ DefaultUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)"
+
errInvalidCertificate = "Invalid SSL certificate (original error: %q)"
errTemporaryNetworkOperation = "This website is temporarily unreachable (original error: %q)"
errPermanentNetworkOperation = "This website is permanently unreachable (original error: %q)"
@@ -47,6 +50,7 @@ type Client struct {
authorizationHeader string
username string
password string
+ userAgent string
Insecure bool
}
@@ -72,6 +76,14 @@ func (c *Client) WithCacheHeaders(etagHeader, lastModifiedHeader string) *Client
return c
}
+// WithUserAgent defines the User-Agent header to use for outgoing requests.
+func (c *Client) WithUserAgent(userAgent string) *Client {
+ if userAgent != "" {
+ c.userAgent = userAgent
+ }
+ return c
+}
+
// Get execute a GET HTTP request.
func (c *Client) Get() (*Response, error) {
request, err := c.buildRequest(http.MethodGet, nil)
@@ -212,7 +224,7 @@ func (c *Client) buildClient() http.Client {
func (c *Client) buildHeaders() http.Header {
headers := make(http.Header)
- headers.Add("User-Agent", "Mozilla/5.0 (compatible; Miniflux/"+version.Version+"; +https://miniflux.app)")
+ headers.Add("User-Agent", c.userAgent)
headers.Add("Accept", "*/*")
if c.etagHeader != "" {
@@ -233,5 +245,5 @@ func (c *Client) buildHeaders() http.Header {
// New returns a new HTTP client.
func New(url string) *Client {
- return &Client{url: url, Insecure: false}
+ return &Client{url: url, userAgent: DefaultUserAgent, Insecure: false}
}