Skip to content

Commit

Permalink
chore: Append OS and arch to User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Nov 14, 2024
1 parent 23d7591 commit 6f75950
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions internal/util/http.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package util

import (
"net/http"
"runtime"
"strings"

"gabe565.com/utils/httpx"
)

func NewUserAgentTransport(name, version string) *UserAgentTransport {
func NewUserAgentTransport(name, version string) *httpx.UserAgentTransport {
ua := name + "/"
commit := strings.TrimPrefix(GetCommit(), "*")
if version != "" {
Expand All @@ -16,19 +18,7 @@ func NewUserAgentTransport(name, version string) *UserAgentTransport {
} else if commit != "" {
ua += commit
}
ua += " (" + runtime.GOOS + "/" + runtime.GOARCH + ")"

return &UserAgentTransport{
transport: http.DefaultTransport,
userAgent: ua,
}
}

type UserAgentTransport struct {
transport http.RoundTripper
userAgent string
}

func (u *UserAgentTransport) RoundTrip(r *http.Request) (*http.Response, error) {
r.Header.Set("User-Agent", u.userAgent)
return u.transport.RoundTrip(r)
return httpx.NewUserAgentTransport(nil, ua)
}

0 comments on commit 6f75950

Please sign in to comment.