Skip to content

Commit

Permalink
Add User-Agent header
Browse files Browse the repository at this point in the history
This makes it easier on server admins to differentiate requests, block
us if they feel our usage is inappropriate and informs them how they can
reach out to us to resolve any issues.
  • Loading branch information
daenney committed Apr 27, 2021
1 parent 41542f8 commit 4957ff0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
)

const (
source = "https://www.vattenfall.se/api/price/spot/pricearea/%s/%s/%s"
source = "https://www.vattenfall.se/api/price/spot/pricearea/%s/%s/%s"
userAgent = "vattenfall-exporter/%s (+https://github.com/daenney/vattenfall)"
)

type Data struct {
Expand Down Expand Up @@ -87,7 +88,15 @@ func fetchFromURL(date time.Time, region string) ([]byte, error) {
date.Format("2006-01-02"),
region,
)
resp, err := http.Get(res)

req, err := http.NewRequest("GET", res, nil)
if err != nil {
return nil, err
}

req.Header.Set("User-Agent", fmt.Sprintf(userAgent, version))

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to fetch %s: %w", res, err)
}
Expand Down

0 comments on commit 4957ff0

Please sign in to comment.