fix: suppress OkHttp default User-Agent header on outbound requests by chrismParticle · Pull Request #29 · mParticle/mparticle-java-events-sdk · GitHub
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

cursor Bot commented May 18, 2026

Copy link
Copy Markdown

@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