Set User-Agent
parent
8f6192e26b
commit
3268207afe
|
@ -370,6 +370,7 @@ func run() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
client := mastodon.NewClient(config)
|
client := mastodon.NewClient(config)
|
||||||
|
client.UserAgent = "mstdn"
|
||||||
app.Metadata = map[string]interface{}{
|
app.Metadata = map[string]interface{}{
|
||||||
"client": client,
|
"client": client,
|
||||||
"config": config,
|
"config": config,
|
||||||
|
|
|
@ -31,7 +31,8 @@ type Config struct {
|
||||||
// Client is a API client for mastodon.
|
// Client is a API client for mastodon.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
http.Client
|
http.Client
|
||||||
config *Config
|
config *Config
|
||||||
|
UserAgent string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) doAPI(ctx context.Context, method string, uri string, params interface{}, res interface{}, pg *Pagination) error {
|
func (c *Client) doAPI(ctx context.Context, method string, uri string, params interface{}, res interface{}, pg *Pagination) error {
|
||||||
|
@ -117,6 +118,9 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
|
||||||
if params != nil {
|
if params != nil {
|
||||||
req.Header.Set("Content-Type", ct)
|
req.Header.Set("Content-Type", ct)
|
||||||
}
|
}
|
||||||
|
if c.UserAgent != "" {
|
||||||
|
req.Header.Set("User-Agent", c.UserAgent)
|
||||||
|
}
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
backoff := 1000 * time.Millisecond
|
backoff := 1000 * time.Millisecond
|
||||||
|
@ -211,6 +215,9 @@ func (c *Client) authenticate(ctx context.Context, params url.Values) error {
|
||||||
}
|
}
|
||||||
req = req.WithContext(ctx)
|
req = req.WithContext(ctx)
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
if c.UserAgent != "" {
|
||||||
|
req.Header.Set("User-Agent", c.UserAgent)
|
||||||
|
}
|
||||||
resp, err := c.Do(req)
|
resp, err := c.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue