Skip to content

fix: suppress OkHttp default User-Agent header on outbound requests#29

Closed
chrismParticle wants to merge 1 commit into
mParticle:mainfrom
chrismParticle:remove-okhttp
Closed

fix: suppress OkHttp default User-Agent header on outbound requests#29
chrismParticle wants to merge 1 commit into
mParticle:mainfrom
chrismParticle:remove-okhttp

Conversation

@chrismParticle
Copy link
Copy Markdown
Contributor

Summary

  • Adds a UserAgentInterceptor (network interceptor) to ApiClient that strips OkHttp's default User-Agent header (okhttp/<version>) after BridgeInterceptor injects it
  • Wired in both createDefaultAdapter() and configureFromOkclient() so all construction paths are covered
  • Caller-supplied User-Agent values (set via a custom OkHttp interceptor) are detected and passed through unchanged
  • This resolves cases where mParticle was enriching device_info.http_header_user_agent with a meaningless library-identifier string

Version

Changelog entry added for 2.8.0.

Test plan

  • New test class ApiClientUserAgentTest covers three cases using MockWebServer: default path (no UA), caller override preserved, and configureFromOkclient path
  • ./gradlew test — 9 tests, all passing
  • Manually verified against mParticle Live Stream: batch without UA shows no device_info.http_header_user_agent; batch with User-Agent: my_app shows my_app correctly

Notes

  • Uses addNetworkInterceptor (not addInterceptor) — required because OkHttp's BridgeInterceptor runs between application and network interceptors and re-injects the default UA if the header is absent at the application layer
  • RateLimitInterceptor is unchanged
  • No public API surface changes

🤖 Generated with Claude Code

Adds a UserAgentInterceptor (network interceptor) to ApiClient that
removes the okhttp/<version> User-Agent header injected by OkHttp's
BridgeInterceptor. This prevents mParticle from enriching
device_info.http_header_user_agent with a meaningless SDK string.
Caller-supplied User-Agent values are preserved. Wired in both
createDefaultAdapter() and configureFromOkclient().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cursor
Copy link
Copy Markdown

cursor Bot commented May 18, 2026

PR Summary

Medium Risk
Changes outbound HTTP header behavior by stripping OkHttp’s default User-Agent, which could affect any downstream systems that relied on that value, though caller-supplied headers are preserved and behavior is covered by new tests.

Overview
Suppresses OkHttp’s default User-Agent on SDK requests. ApiClient now installs a network UserAgentInterceptor that removes User-Agent: okhttp/<version> after OkHttp injects it, while leaving any caller-provided User-Agent untouched (including when using configureFromOkclient).

Adds MockWebServer-backed tests covering default/no-override and override cases, documents the new behavior in README, and records the fix in the 2.8.0 changelog entry.

Reviewed by Cursor Bugbot for commit 8a35aa4. Bugbot is set up for automated code reviews on this repo. Configure here.

@chrismParticle chrismParticle deleted the remove-okhttp branch May 19, 2026 00:03
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.

1 participant