Skip to content

Exclude transient query parameter from identities request when false #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,29 @@ interface FlagsmithRetrofitService {
}
}

fun queryInterceptor(): Interceptor {
return Interceptor { chain ->
val request = chain.request()
if (request.method == "GET" && request.url.pathSegments.contains("identities") && request.url.queryParameter("transient") == "false") {
val url = request.url.newBuilder()
.removeAllQueryParameters("transient")
.build()
val newRequest = request.newBuilder()
.url(url)
.build()
chain.proceed(newRequest)
} else {
chain.proceed(request)
}
}
}

val cache = if (context != null && cacheConfig.enableCache) Cache(context.cacheDir, cacheConfig.cacheSize) else null

val client = OkHttpClient.Builder()
.addInterceptor(envKeyInterceptor(environmentKey))
.addInterceptor(updatedAtInterceptor(timeTracker))
.addInterceptor(queryInterceptor())
.addInterceptor(jsonContentTypeInterceptor())
.let { if (cacheConfig.enableCache) it.addNetworkInterceptor(cacheControlInterceptor()) else it }
.callTimeout(requestTimeoutSeconds, java.util.concurrent.TimeUnit.SECONDS)
Expand Down
15 changes: 15 additions & 0 deletions FlagsmithClient/src/test/java/com/flagsmith/IdentityTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ class IdentityTests {
}
}

@Test(expected = AssertionError::class)
fun testGetIdentityWithExpectedParameterMissing() {
mockServer.mockResponseFor(MockEndpoint.GET_IDENTITIES)
runBlocking {
flagsmith.getIdentitySync("person")

mockServer.verify(
request()
.withPath("/identities/")
.withMethod("GET")
.withQueryStringParameter("transient")
)
}
}

@Test
fun testGetTransientIdentity() {
mockServer.mockResponseFor(MockEndpoint.GET_TRANSIENT_IDENTITIES)
Expand Down
Loading