Skip to content
This repository was archived by the owner on Jun 16, 2026. It is now read-only.

Commit bd75a2e

Browse files
authored
Merge pull request #49 from tailor-platform/chore/set-user-agent
chore: add User-Agent header to Tailor Platform API requests
2 parents c6f2e7e + 7de4129 commit bd75a2e

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

tailor/tailor.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package tailor
22

33
import (
44
"errors"
5+
"fmt"
56
"net/http"
67
"os"
78

89
"buf.build/gen/go/tailor-inc/tailor/connectrpc/go/tailor/v1/tailorv1connect"
910
"github.com/tailor-platform/patterner/config"
11+
"github.com/tailor-platform/patterner/version"
1012
)
1113

1214
type Client struct {
@@ -27,13 +29,14 @@ func New(cfg *config.Config) (*Client, error) {
2729
baseURL = platformURL
2830
}
2931

30-
// Create HTTP client with Bearer token authorization
32+
// Create HTTP client with Bearer token authorization and User-Agent
3133
httpClient := &http.Client{}
3234
if token := os.Getenv("TAILOR_TOKEN"); token != "" {
3335
httpClient = &http.Client{
3436
Transport: &bearerTokenTransport{
35-
token: token,
36-
base: http.DefaultTransport,
37+
token: token,
38+
userAgent: fmt.Sprintf("%s/%s", version.Name, version.Version),
39+
base: http.DefaultTransport,
3740
},
3841
}
3942
}
@@ -44,13 +47,15 @@ func New(cfg *config.Config) (*Client, error) {
4447
}, nil
4548
}
4649

47-
// bearerTokenTransport implements http.RoundTripper to add Bearer token to requests.
50+
// bearerTokenTransport implements http.RoundTripper to add Bearer token and User-Agent to requests.
4851
type bearerTokenTransport struct {
49-
token string
50-
base http.RoundTripper
52+
token string
53+
userAgent string
54+
base http.RoundTripper
5155
}
5256

5357
func (t *bearerTokenTransport) RoundTrip(req *http.Request) (*http.Response, error) {
5458
req.Header.Set("Authorization", "Bearer "+t.token)
59+
req.Header.Set("User-Agent", t.userAgent)
5560
return t.base.RoundTrip(req)
5661
}

0 commit comments

Comments
 (0)