feat: add custom User-Agent header to identify CLI traffic#17
Merged
feat: add custom User-Agent header to identify CLI traffic#17
Conversation
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.
UserAgent is always set by the factory in client_factory.go, so the != "" checks were dead code adding unnecessary complexity.
jasonjul
approved these changes
Mar 16, 2026
Collaborator
|
Need someone from your team to approve @khooihzhz |
ElvisLYC
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
User-Agent: coingecko-cli/{version}to all HTTP API requests and WebSocket handshakes for server-side traffic attributionapi.Clientandws.Client, injected via the factory functions incmd/client_factory.go— no mutable package-level state--dry-runoutput now includes theUser-AgentheaderTest plan
TestUserAgentHeader— verifies header is sent on HTTP API requestsTestUserAgentHeaderOmittedWhenEmpty— verifies Go default UA when field is unsetTestConnect_UserAgentHeader— verifies header is sent during WebSocket handshakego test -race ./...passesgolangci-lintpasses./cg price --ids bitcoin --dry-runshows"User-Agent": "coingecko-cli/dev"