From 99dc590e459eb760a3aae963226ff843c2f51917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Mon, 18 Dec 2017 17:59:35 -0800 Subject: [PATCH] Change user agent to bypass some website restrictions --- http/client.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/http/client.go b/http/client.go index 84738264..9524dd67 100644 --- a/http/client.go +++ b/http/client.go @@ -15,7 +15,8 @@ import ( "github.com/miniflux/miniflux/logger" ) -const userAgent = "Miniflux " +// Note: Some websites have a user agent filter. +const userAgent = "Mozilla/5.0 (like Gecko, like Safari, like Chrome) - Miniflux " const requestTimeout = 300 // Client is a HTTP Client :) @@ -47,12 +48,12 @@ func (c *Client) Get() (*Response, error) { ContentType: resp.Header.Get("Content-Type"), } - logger.Debug("[HttpClient:Get]", - "OriginalURL:", c.url, - "StatusCode:", response.StatusCode, - "ETag:", response.ETag, - "LastModified:", response.LastModified, - "EffectiveURL:", response.EffectiveURL, + logger.Debug("[HttpClient:Get] OriginalURL=%s, StatusCode=%d, ETag=%s, LastModified=%s, EffectiveURL=%s", + c.url, + response.StatusCode, + response.ETag, + response.LastModified, + response.EffectiveURL, ) return response, err @@ -87,6 +88,7 @@ func (c *Client) buildClient() http.Client { func (c *Client) buildHeaders() http.Header { headers := make(http.Header) headers.Add("User-Agent", userAgent) + headers.Add("Accept", "text/html,application/xhtml+xml,application/xml,application/json") if c.etagHeader != "" { headers.Add("If-None-Match", c.etagHeader)