Skip to content

Commit

Permalink
Fix HTTP header handling
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lerch committed Sep 2, 2024
1 parent 9ee7518 commit 274b3f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
)

type DynClient struct {
client *http.Client
client *http.Client
userAgent string
}

func NewDynClient() *DynClient {
return &DynClient{&http.Client{}}
func NewDynClient(userAgent string) *DynClient {
return &DynClient{&http.Client{}, userAgent}
}

func (c *DynClient) Update(record Record, ip net.IP) (string, string, error) {
Expand All @@ -40,6 +41,15 @@ func (c *DynClient) Update(record Record, ip net.IP) (string, string, error) {
return "", urlWithoutPassword, err
}

request.Header.Set("User-Agent", c.userAgent)
for _, header := range record.Headers {
name, value, found := strings.Cut(header, ":")
if !found {
return "", urlWithoutPassword, errors.New("Invalid header: " + header)
}
request.Header.Set(name, value)
}

response, err := c.client.Do(request)
if err != nil {
return "", urlWithoutPassword, err
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
return
}

client := NewDynClient()
client := NewDynClient(settings.UserAgent)

UpdateOnStartup(settings, client)

Expand Down

0 comments on commit 274b3f9

Please sign in to comment.