Skip to content

Commit 94fcd91

Browse files
authored
fix: send pipeboard-cli User-Agent on all HTTP requests (#14)
RESTClient and FetchToolsHash were using Go default User-Agent (Go-http-client/1.1). Now all HTTP paths consistently send pipeboard-cli/<version>.
1 parent 6f634c6 commit 94fcd91

5 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎cmd/debug.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func runDebugMetaAds(cmd *cobra.Command, args []string) error {
132132
body["ad_account_id"] = debugMetaAdAccountID
133133
}
134134

135-
c := client.NewREST(getWebAPIURL(), token)
135+
c := client.NewREST(getWebAPIURL(), token, Version)
136136
result, err := c.Post("/api/debug/meta-ads", body)
137137
if err != nil {
138138
return fmt.Errorf("debug query failed: %w", err)

‎cmd/dynamic.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func maybeAutoRefresh(cache *ToolsCache) {
7979
func runAutoRefresh(baseURL, token string) error {
8080
cache, _ := loadToolsCache()
8181

82-
hashResult, err := client.FetchToolsHash(baseURL)
82+
hashResult, err := client.FetchToolsHash(baseURL, Version)
8383
if err != nil {
8484
return err
8585
}

‎cmd/refresh.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func fetchAndCacheTools(baseURL, token string, verbose bool) (*ToolsCache, error
8989
}
9090

9191
// Fetch and store the current hash
92-
if hashResult, err := client.FetchToolsHash(baseURL); err == nil {
92+
if hashResult, err := client.FetchToolsHash(baseURL, Version); err == nil {
9393
cache.Hash = hashResult.Hash
9494
}
9595

‎internal/client/mcp.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,14 @@ type ToolsHashResult struct {
179179
// FetchToolsHash retrieves the combined tools hash from the server.
180180
// baseURL is the MCP base URL (e.g. https://mcp.pipeboard.co).
181181
// This endpoint requires no authentication.
182-
func FetchToolsHash(baseURL string) (*ToolsHashResult, error) {
183-
resp, err := http.Get(baseURL + "/api/tools-hash")
182+
func FetchToolsHash(baseURL, version string) (*ToolsHashResult, error) {
183+
req, err := http.NewRequest("GET", baseURL+"/api/tools-hash", nil)
184+
if err != nil {
185+
return nil, fmt.Errorf("creating request: %w", err)
186+
}
187+
req.Header.Set("User-Agent", "pipeboard-cli/"+version)
188+
189+
resp, err := http.DefaultClient.Do(req)
184190
if err != nil {
185191
return nil, fmt.Errorf("fetching tools hash: %w", err)
186192
}

‎internal/client/rest.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import (
1212
type RESTClient struct {
1313
baseURL string
1414
token string
15+
userAgent string
1516
httpClient *http.Client
1617
}
1718

18-
// NewREST creates a REST API client.
19-
func NewREST(baseURL, token string) *RESTClient {
19+
// NewREST creates a REST API client. version is used in the User-Agent header.
20+
func NewREST(baseURL, token, version string) *RESTClient {
2021
return &RESTClient{
2122
baseURL: baseURL,
2223
token: token,
24+
userAgent: "pipeboard-cli/" + version,
2325
httpClient: &http.Client{},
2426
}
2527
}
@@ -39,6 +41,7 @@ func (c *RESTClient) Post(path string, body interface{}) (map[string]interface{}
3941

4042
req.Header.Set("Content-Type", "application/json")
4143
req.Header.Set("Authorization", "Bearer "+c.token)
44+
req.Header.Set("User-Agent", c.userAgent)
4245

4346
resp, err := c.httpClient.Do(req)
4447
if err != nil {

0 commit comments

Comments
 (0)