Browse Source

Add User-Agent header

prplecake 2 years ago
parent
commit
7263b5702a
2 changed files with 11 additions and 0 deletions
  1. 10 0
      config.go
  2. 1 0
      message.go

+ 10 - 0
config.go

@@ -8,6 +8,10 @@ import (
 	"gopkg.in/yaml.v2"
 )
 
+const (
+	HttpUserAgent = "gof"
+)
+
 var (
 	configFile string
 )
@@ -23,6 +27,7 @@ type feed struct {
 type config struct {
 	Accounts    []account
 	LastUpdated time.Time
+	HttpConfig  httpConfig
 }
 
 type account struct {
@@ -32,6 +37,10 @@ type account struct {
 	Feeds       []feed
 }
 
+type httpConfig struct {
+	UserAgent string
+}
+
 func readConfig(fileName string) *config {
 	log.Println("reading config...")
 	configFile = fileName
@@ -47,6 +56,7 @@ func readConfig(fileName string) *config {
 	if debug {
 		log.Printf("Config:\n\n%v", config)
 	}
+	config.HttpConfig.UserAgent = HttpUserAgent
 	return config
 }
 

+ 1 - 0
message.go

@@ -65,6 +65,7 @@ func (msg *message) post() error {
 	// Set Headers
 	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
 	req.Header.Set("Authorization", "Bearer "+msg.account.AccessToken)
+	req.Header.Set("User-Agent", conf.HttpConfig.UserAgent)
 
 	c := &http.Client{Timeout: time.Second * 10}