mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Add support for setting a global default User-Agent
This commit is contained in:
parent
b8b6c74d86
commit
52a626d7b9
4 changed files with 40 additions and 2 deletions
|
@ -4,7 +4,12 @@
|
|||
|
||||
package client // import "miniflux.app/http/client"
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"miniflux.app/config"
|
||||
)
|
||||
|
||||
func TestClientWithDelay(t *testing.T) {
|
||||
clt := New("http://httpbin.org/delay/5")
|
||||
|
@ -49,3 +54,21 @@ 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("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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue