refactor: centralize User-Agent header via shared httputil package - #79
Merged
steve-calvert-glean merged 1 commit intoApr 6, 2026
Merged
Conversation
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 <noreply@anthropic.com>
rwjblue-glean
marked this pull request as ready for review
April 6, 2026 20:19
steve-calvert-glean
approved these changes
Apr 6, 2026
steve-calvert-glean
deleted the
rwjblue/refactor-centralize-useragent-httputil
branch
April 6, 2026 22:35
pavlo-v-chernykh
added a commit
to pavlo-v-chernykh/glean-cli
that referenced
this pull request
Apr 9, 2026
…est helper PR gleanwork#79 removed the package-level discoveryHTTPClient var from discovery.go and inlined httputil.NewHTTPClient at each call site. The device.go file (added in a parallel branch) still referenced the deleted var, causing a build failure after rebase. Inline the client at both device.go call sites to match the rest of the auth package, and remove the now-unnecessary overrideDiscoveryHTTPClient helper and all 16 calls across test files (httptest.NewServer creates a real TCP server reachable by any client).
steve-calvert-glean
pushed a commit
that referenced
this pull request
Apr 10, 2026
…est helper PR #79 removed the package-level discoveryHTTPClient var from discovery.go and inlined httputil.NewHTTPClient at each call site. The device.go file (added in a parallel branch) still referenced the deleted var, causing a build failure after rebase. Inline the client at both device.go call sites to match the rest of the auth package, and remove the now-unnecessary overrideDiscoveryHTTPClient helper and all 16 calls across test files (httptest.NewServer creates a real TCP server reachable by any client).
steve-calvert-glean
added a commit
that referenced
this pull request
Apr 10, 2026
* feat: add Device Authorization Grant (RFC 8628) as login fallback When DCR is unavailable (e.g. Okta SSO), auth login now falls back to the OAuth 2.0 Device Authorization Grant. The user approves login on a verification page instead of a local redirect. * fix: narrow device flow fallback to DCR-unavailable errors only The previous fallback triggered on any tryAuthCodeLogin failure, including transient issues like network timeouts or the user closing their browser. Now device flow only activates when dcrOrStaticClient returns errNoOAuthClient (no registration endpoint + no static client), not when DCR was attempted and failed. Made-with: Cursor * refactor: inline httputil.NewHTTPClient in device flow, remove dead test helper PR #79 removed the package-level discoveryHTTPClient var from discovery.go and inlined httputil.NewHTTPClient at each call site. The device.go file (added in a parallel branch) still referenced the deleted var, causing a build failure after rebase. Inline the client at both device.go call sites to match the rest of the auth package, and remove the now-unnecessary overrideDiscoveryHTTPClient helper and all 16 calls across test files (httptest.NewServer creates a real TCP server reachable by any client). * refactor: add debug logging to device flow, improve auth UX and README - Add auth:device debug namespace for tracing device flow login - Improve fallback message: "Your SSO provider requires device-based login" instead of confusing OAuth jargon - Rewrite README auth section with scannable table showing three login methods and when each is used - Add "Credential resolution order" subsection - Note that API tokens are scoped to individual user accounts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Steve Calvert <steve.calvert@glean.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
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 theglean apicommand all used barehttp.Client{}instances with no user-agent set.This adds an
internal/httputilpackage that centralizes both the CLI version string and User-Agent injection into a single place. All HTTP clients now go throughhttputil.NewHTTPClient(timeout)or compose onhttputil.NewTransport(base), which guarantees every outbound request identifies itself.As part of this, the
cliTransporttype ininternal/clientis eliminated — its only remaining job (injectingX-Glean-Auth-Typefor OAuth tokens) is now handled byhttputil.WithHeader, a general-purpose option onNewTransport.