Skip to content

Commit

Permalink
chore(util): Use go-utils UserAgentTransport implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Nov 11, 2024
1 parent f7fcc0f commit fd708e8
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions internal/util/http.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package util

import (
"net/http"
"os"
"path/filepath"
"runtime"

"gabe565.com/utils/httpx"
)

func NewUserAgentTransport() *UserAgentTransport {
func NewUserAgentTransport() *httpx.UserAgentTransport {
ua := filepath.Base(os.Args[0])
if version := GetVersion(); version != "" {
ua += "/v" + version
Expand All @@ -19,18 +20,5 @@ func NewUserAgentTransport() *UserAgentTransport {
}
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 fd708e8

Please # to comment.