Skip to content

Commit

Permalink
client: add X-Savvy-Version req Header
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed Jan 7, 2024
1 parent 591b241 commit 93e45e2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func New() (Client, error) {
c := &client{
cl: &http.Client{
Transport: &AuthorizedRoundTripper{
token: cfg.Token,
token: cfg.Token,
savvyVersion: config.Version(),
},
},
apiHost: config.APIHost(),
Expand All @@ -50,13 +51,15 @@ func New() (Client, error) {
}

type AuthorizedRoundTripper struct {
token string
token string
savvyVersion string
}

func (a *AuthorizedRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
// Clone the request to ensure thread safety
clonedReq := req.Clone(req.Context())
clonedReq.Header.Set("Authorization", "Bearer "+a.token)
clonedReq.Header.Set("X-Savvy-Version", a.savvyVersion)

// Use the embedded Transport to perform the actual request
res, err := http.DefaultTransport.RoundTrip(clonedReq)
Expand Down

0 comments on commit 93e45e2

Please sign in to comment.