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