Show correct User Agent in input placeholders
This commit is contained in:
parent
e589a35c67
commit
2cf9bde1af
15 changed files with 37 additions and 64 deletions
|
@ -7,6 +7,8 @@ package config // import "miniflux.app/config"
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"miniflux.app/version"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -52,7 +54,6 @@ const (
|
|||
defaultHTTPClientTimeout = 20
|
||||
defaultHTTPClientMaxBodySize = 15
|
||||
defaultHTTPClientProxy = ""
|
||||
defaultHTTPClientUserAgent = ""
|
||||
defaultAuthProxyHeader = ""
|
||||
defaultAuthProxyUserCreation = false
|
||||
defaultMaintenanceMode = false
|
||||
|
@ -62,6 +63,8 @@ const (
|
|||
defaultMetricsAllowedNetworks = "127.0.0.1/8"
|
||||
)
|
||||
|
||||
var defaultHTTPClientUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)"
|
||||
|
||||
// Options contains configuration options.
|
||||
type Options struct {
|
||||
HTTPS bool
|
||||
|
@ -159,6 +162,7 @@ func NewOptions() *Options {
|
|||
httpClientTimeout: defaultHTTPClientTimeout,
|
||||
httpClientMaxBodySize: defaultHTTPClientMaxBodySize * 1024 * 1024,
|
||||
httpClientProxy: defaultHTTPClientProxy,
|
||||
httpClientUserAgent: defaultHTTPClientUserAgent,
|
||||
authProxyHeader: defaultAuthProxyHeader,
|
||||
authProxyUserCreation: defaultAuthProxyUserCreation,
|
||||
maintenanceMode: defaultMaintenanceMode,
|
||||
|
@ -166,7 +170,6 @@ func NewOptions() *Options {
|
|||
metricsCollector: defaultMetricsCollector,
|
||||
metricsRefreshInterval: defaultMetricsRefreshInterval,
|
||||
metricsAllowedNetworks: []string{defaultMetricsAllowedNetworks},
|
||||
httpClientUserAgent: defaultHTTPClientUserAgent,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"miniflux.app/logger"
|
||||
"miniflux.app/timer"
|
||||
url_helper "miniflux.app/url"
|
||||
"miniflux.app/version"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -31,9 +30,6 @@ 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)"
|
||||
|
@ -64,7 +60,6 @@ type Client struct {
|
|||
func New(url string) *Client {
|
||||
return &Client{
|
||||
inputURL: url,
|
||||
requestUserAgent: DefaultUserAgent,
|
||||
ClientTimeout: defaultHTTPClientTimeout,
|
||||
ClientMaxBodySize: defaultHTTPClientMaxBodySize,
|
||||
}
|
||||
|
@ -72,13 +67,9 @@ func New(url string) *Client {
|
|||
|
||||
// NewClientWithConfig initializes a new HTTP client with application config options.
|
||||
func NewClientWithConfig(url string, opts *config.Options) *Client {
|
||||
userAgent := opts.HTTPClientUserAgent()
|
||||
if userAgent == "" {
|
||||
userAgent = DefaultUserAgent
|
||||
}
|
||||
return &Client{
|
||||
inputURL: url,
|
||||
requestUserAgent: userAgent,
|
||||
requestUserAgent: opts.HTTPClientUserAgent(),
|
||||
ClientTimeout: opts.HTTPClientTimeout(),
|
||||
ClientMaxBodySize: opts.HTTPClientMaxBodySize(),
|
||||
ClientProxyURL: opts.HTTPClientProxy(),
|
||||
|
@ -321,9 +312,12 @@ func (c *Client) buildClient() http.Client {
|
|||
|
||||
func (c *Client) buildHeaders() http.Header {
|
||||
headers := make(http.Header)
|
||||
headers.Add("User-Agent", c.requestUserAgent)
|
||||
headers.Add("Accept", "*/*")
|
||||
|
||||
if c.requestUserAgent != "" {
|
||||
headers.Add("User-Agent", c.requestUserAgent)
|
||||
}
|
||||
|
||||
if c.requestEtagHeader != "" {
|
||||
headers.Add("If-None-Match", c.requestEtagHeader)
|
||||
}
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
package client // import "miniflux.app/http/client"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"miniflux.app/config"
|
||||
)
|
||||
|
||||
func TestClientWithDelay(t *testing.T) {
|
||||
|
@ -54,21 +51,3 @@ func TestClientWithBasicAuth(t *testing.T) {
|
|||
t.Fatalf(`The client should be authenticated successfully: %v`, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientRequestUserAgent(t *testing.T) {
|
||||
clt := New("http://httpbin.org")
|
||||
if clt.requestUserAgent != DefaultUserAgent {
|
||||
t.Errorf(`The client had default User-Agent %q, wanted %q`, clt.requestUserAgent, DefaultUserAgent)
|
||||
}
|
||||
|
||||
userAgent := "Custom User Agent"
|
||||
os.Setenv("HTTP_CLIENT_USER_AGENT", userAgent)
|
||||
opts, err := config.NewParser().ParseEnvironmentVariables()
|
||||
if err != nil {
|
||||
t.Fatalf(`Parsing config failed: %v`, err)
|
||||
}
|
||||
clt = NewClientWithConfig("http://httpbin.org", opts)
|
||||
if clt.requestUserAgent != userAgent {
|
||||
t.Errorf(`The client had User-Agent %q, wanted %q`, clt.requestUserAgent, userAgent)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/ui/form"
|
||||
|
@ -68,7 +67,7 @@ func (h *handler) showEditFeedPage(w http.ResponseWriter, r *http.Request) {
|
|||
view.Set("user", user)
|
||||
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
||||
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
||||
view.Set("defaultUserAgent", client.DefaultUserAgent)
|
||||
view.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
|
||||
view.Set("hasProxyConfigured", config.Opts.HasHTTPClientProxyConfigured())
|
||||
|
||||
html.OK(w, r, view.Render("edit_feed"))
|
||||
|
|
|
@ -7,7 +7,7 @@ package ui // import "miniflux.app/ui"
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
|
@ -53,7 +53,7 @@ func (h *handler) updateFeed(w http.ResponseWriter, r *http.Request) {
|
|||
view.Set("user", user)
|
||||
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
||||
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
||||
view.Set("defaultUserAgent", client.DefaultUserAgent)
|
||||
view.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
|
||||
|
||||
if err := feedForm.ValidateModification(); err != nil {
|
||||
view.Set("errorMessage", err.Error())
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/crypto"
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
|
@ -46,7 +45,7 @@ func (h *handler) imageProxy(w http.ResponseWriter, r *http.Request) {
|
|||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
req.Header.Add("User-Agent", client.DefaultUserAgent)
|
||||
req.Header.Add("User-Agent", config.Opts.HTTPClientUserAgent())
|
||||
req.Header.Add("Connection", "close")
|
||||
|
||||
clt := &http.Client{
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -404,10 +404,8 @@ textarea:focus {
|
|||
box-shadow: var(--input-focus-box-shadow);
|
||||
}
|
||||
|
||||
::-moz-placeholder,
|
||||
::-ms-input-placeholder,
|
||||
::-webkit-input-placeholder {
|
||||
color: #ddd;
|
||||
input::placeholder {
|
||||
color: var(--input-placeholder-color);
|
||||
padding-top: 2px;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
--input-border: 1px solid #555;
|
||||
--input-background: #333;
|
||||
--input-color: #ccc;
|
||||
--input-placeholder-color: #666;
|
||||
|
||||
--input-focus-color: #efefef;
|
||||
--input-focus-border-color: rgba(82, 168, 236, 0.8);
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
--input-border: 1px solid #ccc;
|
||||
--input-background: #fff;
|
||||
--input-color: #333;
|
||||
--input-placeholder-color: #d0d0d0;
|
||||
|
||||
--input-focus-color: #000;
|
||||
--input-focus-border-color: rgba(82, 168, 236, 0.8);
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
--input-border: 1px solid #ccc;
|
||||
--input-background: #fff;
|
||||
--input-color: #333;
|
||||
--input-placeholder-color: #d0d0d0;
|
||||
|
||||
--input-focus-color: #000;
|
||||
--input-focus-border-color: rgba(82, 168, 236, 0.8);
|
||||
|
@ -139,6 +140,7 @@
|
|||
--input-border: 1px solid #555;
|
||||
--input-background: #333;
|
||||
--input-color: #ccc;
|
||||
--input-placeholder-color: #666;
|
||||
|
||||
--input-focus-color: #efefef;
|
||||
--input-focus-border-color: rgba(82, 168, 236, 0.8);
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/ui/form"
|
||||
|
@ -37,7 +36,7 @@ func (h *handler) showAddSubscriptionPage(w http.ResponseWriter, r *http.Request
|
|||
view.Set("user", user)
|
||||
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
||||
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
||||
view.Set("defaultUserAgent", client.DefaultUserAgent)
|
||||
view.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
|
||||
view.Set("form", &form.SubscriptionForm{CategoryID: 0})
|
||||
view.Set("hasProxyConfigured", config.Opts.HasHTTPClientProxyConfigured())
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/ui/form"
|
||||
|
@ -40,7 +39,7 @@ func (h *handler) bookmarklet(w http.ResponseWriter, r *http.Request) {
|
|||
view.Set("user", user)
|
||||
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
||||
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
||||
view.Set("defaultUserAgent", client.DefaultUserAgent)
|
||||
view.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
|
||||
view.Set("hasProxyConfigured", config.Opts.HasHTTPClientProxyConfigured())
|
||||
|
||||
html.OK(w, r, view.Render("add_subscription"))
|
||||
|
|
|
@ -7,7 +7,7 @@ package ui // import "miniflux.app/ui"
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
|
@ -37,7 +37,7 @@ func (h *handler) showChooseSubscriptionPage(w http.ResponseWriter, r *http.Requ
|
|||
view.Set("user", user)
|
||||
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
||||
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
||||
view.Set("defaultUserAgent", client.DefaultUserAgent)
|
||||
view.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
|
||||
|
||||
subscriptionForm := form.NewSubscriptionForm(r)
|
||||
if err := subscriptionForm.Validate(); err != nil {
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/config"
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
|
@ -40,7 +39,7 @@ func (h *handler) submitSubscription(w http.ResponseWriter, r *http.Request) {
|
|||
v.Set("user", user)
|
||||
v.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
||||
v.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
||||
v.Set("defaultUserAgent", client.DefaultUserAgent)
|
||||
v.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
|
||||
v.Set("hasProxyConfigured", config.Opts.HasHTTPClientProxyConfigured())
|
||||
|
||||
subscriptionForm := form.NewSubscriptionForm(r)
|
||||
|
|
Loading…
Reference in a new issue