Skip to content

refactor: centralize User-Agent header via shared httputil package#79

Merged
steve-calvert-glean merged 1 commit intomainfrom
rwjblue/refactor-centralize-useragent-httputil
Apr 6, 2026
Merged

refactor: centralize User-Agent header via shared httputil package#79
steve-calvert-glean merged 1 commit intomainfrom
rwjblue/refactor-centralize-useragent-httputil

Conversation

@rwjblue-glean
Copy link
Copy Markdown
Member

Requests routed through the Glean Go SDK and the streaming chat endpoint were correctly sending User-Agent: glean-cli/<version>, but several other HTTP call sites were not — OAuth discovery, dynamic client registration, domain lookup, GitHub release checks, and the glean api command all used bare http.Client{} instances with no user-agent set.

This adds an internal/httputil package that centralizes both the CLI version string and User-Agent injection into a single place. All HTTP clients now go through httputil.NewHTTPClient(timeout) or compose on httputil.NewTransport(base), which guarantees every outbound request identifies itself.

As part of this, the cliTransport type in internal/client is eliminated — its only remaining job (injecting X-Glean-Auth-Type for OAuth tokens) is now handled by httputil.WithHeader, a general-purpose option on NewTransport.

Add internal/httputil package that owns the CLI version string and
provides NewHTTPClient/NewTransport to inject User-Agent on all
outbound HTTP requests. Previously only SDK and streaming chat
requests set the header; auth discovery, domain lookup, update
checks, and the api command did not.

- NewTransport wraps any RoundTripper with UA injection + optional
  extra headers via WithHeader option
- Eliminates cliTransport from internal/client (X-Glean-Auth-Type
  now handled via httputil.WithHeader)
- Removes duplicated SetVersion/Version from internal/client
- Migrates all 7 HTTP call sites to use the shared factory

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@rwjblue-glean rwjblue-glean marked this pull request as ready for review April 6, 2026 20:19
@steve-calvert-glean steve-calvert-glean merged commit c23e798 into main Apr 6, 2026
7 checks passed
@steve-calvert-glean steve-calvert-glean deleted the rwjblue/refactor-centralize-useragent-httputil branch April 6, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants