Skip to content

Commit

Permalink
Set Version in User-Agent (#459)
Browse files Browse the repository at this point in the history
Co-authored-by: Rasmus Karlsson <[email protected]>
  • Loading branch information
M4tthewDE and pajlada authored Apr 4, 2023
1 parent 8dfebc7 commit 3ba49f3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Minor: Our User-Agent now properly reflects the version of the API. (#459)

## 2.0.1

- Minor: Added support for FrankerFaceZ animated emote links. (#455)
Expand Down
3 changes: 2 additions & 1 deletion docs/make-release.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Make a release

1. Make a PR onto the main branch that updates the version in the changelog:
Insert version (e.g. `## 1.2.3`) inbetween `## Unreleased` and the included changelog entries
Insert version (e.g. `## 1.2.3`) inbetween `## Unreleased` and the included changelog entries.
Update the version in `internal/version/version.go`.
2. Get the PR merged into the main branch
3. Once the main branch has had its CI steps run, create a tag on that commit and push it:
`git tag -a v1.2.3 -m "Release v1.2.3" && git push origin v1.2.3`
3 changes: 3 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

const Version = "2.0.1"
7 changes: 5 additions & 2 deletions pkg/resolver/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package resolver

import (
"context"
"fmt"
"net/http"
"strings"
"time"

"github.com/Chatterino/api/internal/logger"
"github.com/Chatterino/api/internal/version"
)

var (
Expand All @@ -29,7 +31,7 @@ func RequestGET(ctx context.Context, url string) (response *http.Response, err e
// ensures websites return pages in english (e.g. twitter would return french preview
// when the request came from a french IP.)
req.Header.Add("Accept-Language", "en-US, en;q=0.9, *;q=0.5")
req.Header.Set("User-Agent", "chatterino-api-cache/1.0 link-resolver")
req.Header.Set("User-Agent", fmt.Sprintf("chatterino-api-cache/%s link-resolver", version.Version))

return httpClient.Do(req)
}
Expand All @@ -43,7 +45,7 @@ func RequestGETWithHeaders(url string, extraHeaders map[string]string) (response
// ensures websites return pages in english (e.g. twitter would return french preview
// when the request came from a french IP.)
req.Header.Add("Accept-Language", "en-US, en;q=0.9, *;q=0.5")
req.Header.Set("User-Agent", "chatterino-api-cache/1.0 link-resolver")
req.Header.Set("User-Agent", fmt.Sprintf("chatterino-api-cache/%s link-resolver", version.Version))

for headerKey, headerValue := range extraHeaders {
req.Header.Set(headerKey, headerValue)
Expand All @@ -59,6 +61,7 @@ func RequestPOST(url, body string) (response *http.Response, err error) {
}

req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", fmt.Sprintf("chatterino-api-cache/%s link-resolver", version.Version))

return httpClient.Do(req)
}
Expand Down

0 comments on commit 3ba49f3

Please sign in to comment.