Skip to content

Conversation

@gazreese
Copy link
Collaborator

@gazreese gazreese commented Nov 3, 2025

Fixes https://foresight.slite.com/app/docs/vY7NnrbUCj35XE#ccb66bd3-d784-4e5d-bf6e-8559bb0a76d6

Previous review and subsequent fixes on the Foresight side: foresightmobile#1

Description

Added a User-Agent HTTP header to network calls. Uses the package's version at runtime, if it is not available sends it as "unknown"

Also added a PR template, once this merged new PRs will come with this PR template.

Regression Test Recommendations

Test that User-Agent header is present in all HTTP requests with correct format: flagsmith-swift-ios-sdk/
Test fallback to "unknown" when version is not discoverable at runtime
Validate User-Agent appears in both REST API calls and SSE connections
Type of Change
✨ New feature (non-breaking change which adds functionality)
🛠️ Bug fix (non-breaking change which fixes an issue)
❌ Breaking change (fix or feature that would cause existing functionality to change)
🧹 Code refactor
✅ Build configuration change
📝 Documentation
🗑️ Chore
Summary by CodeRabbit
New Features

Adds a dynamic User-Agent header to network requests that reflects the SDK/app version when available.
Real-time updates initialization now accepts Android context for more reliable behavior on devices.
Tests

New unit tests validating User-Agent composition and that the header is sent across various request types and failure scenarios.

@gazreese gazreese requested a review from a team as a code owner November 3, 2025 09:46
@gazreese gazreese requested review from Zaimwa9, emyller and matthewelwell and removed request for a team November 3, 2025 09:46
Copy link

@emyller emyller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall! Couple questions.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to somehow mock the version so it can be seen in at least one test? All current tests only verify unknown is added in the header.

Comment on lines +50 to +60
private fun getSdkVersion(): String {
return try {
// Try to get version from BuildConfig
val buildConfigClass = Class.forName("com.flagsmith.kotlin.BuildConfig")
val versionField = buildConfigClass.getField("VERSION_NAME")
versionField.get(null) as String
} catch (e: Exception) {
// Fallback to hardcoded version if BuildConfig is not available
"unknown"
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Android machinery used to obtain the Flagsmith client version more reliable than iOS'? I'm asking considering the equivalent pull request to iOS (Flagsmith/flagsmith-ios-client#95) falls back to a hardcoded version string when obtaining the lib version fails, and I wonder why the same strategy isn't used here as well. (I'm not asking we implement it)

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.

3 participants