Skip to content

feat: add custom User-Agent header to identify CLI traffic#17

Merged
khooihzhz merged 3 commits intomainfrom
feat/custom-user-agent
Mar 18, 2026
Merged

feat: add custom User-Agent header to identify CLI traffic#17
khooihzhz merged 3 commits intomainfrom
feat/custom-user-agent

Conversation

@khooihzhz
Copy link
Collaborator

Summary

  • Adds User-Agent: coingecko-cli/{version} to all HTTP API requests and WebSocket handshakes for server-side traffic attribution
  • User-Agent is a struct field on api.Client and ws.Client, injected via the factory functions in cmd/client_factory.go — no mutable package-level state
  • --dry-run output now includes the User-Agent header

Test plan

  • TestUserAgentHeader — verifies header is sent on HTTP API requests
  • TestUserAgentHeaderOmittedWhenEmpty — verifies Go default UA when field is unset
  • TestConnect_UserAgentHeader — verifies header is sent during WebSocket handshake
  • go test -race ./... passes
  • golangci-lint passes
  • ./cg price --ids bitcoin --dry-run shows "User-Agent": "coingecko-cli/dev"

Sets User-Agent to "coingecko-cli/{version}" on all HTTP API requests
and WebSocket handshakes, enabling server-side traffic attribution.

User-Agent is a struct field on api.Client and ws.Client, injected via
the factory functions in client_factory.go — no mutable package-level
state.
Closes the coverage gap noted in the review — verifies User-Agent
header is sent during the WebSocket upgrade handshake.
@khooihzhz khooihzhz requested a review from a team March 16, 2026 08:42
UserAgent is always set by the factory in client_factory.go, so the
!= "" checks were dead code adding unnecessary complexity.
@khooihzhz khooihzhz requested a review from jasonjul March 16, 2026 08:45
@jasonjul
Copy link
Collaborator

Need someone from your team to approve @khooihzhz

Copy link

@bryanleehw97 bryanleehw97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@khooihzhz khooihzhz merged commit d2e9e88 into main Mar 18, 2026
3 checks passed
@khooihzhz khooihzhz deleted the feat/custom-user-agent branch March 18, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants