Skip to content

Commit 2d42f3f

Browse files
authored
Fix custom URL override issue (#30)
* Fix custom URL override issue * Bump versions * Format
1 parent ea7a1fb commit 2d42f3f

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group=com.configcat
2-
version=3.0.0
2+
version=3.0.1
33

44
ktor_version=2.0.3
55
kotlinx_serialization_version=1.4.1

src/commonMain/kotlin/com/configcat/Constants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal interface Closeable {
2020
}
2121

2222
internal object Constants {
23-
const val version: String = "3.0.0"
23+
const val version: String = "3.0.1"
2424
const val configFileName: String = "config_v6.json"
2525
const val serializationFormatVersion: String = "v2"
2626
const val globalCdnUrl = "https://cdn-global.configcat.com"

src/commonMain/kotlin/com/configcat/fetch/ConfigFetcher.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,31 @@ internal class ConfigFetcher constructor(
3131
)
3232

3333
suspend fun fetch(eTag: String): FetchResponse {
34-
val currentUrl = baseUrl.value
35-
val response = fetchHTTPWithPreferenceHandling(currentUrl, eTag)
36-
val newUrl = response.entry.config.preferences?.baseUrl ?: currentUrl
37-
baseUrl.update { newUrl }
38-
return response
34+
return fetchHTTPWithPreferenceHandling(eTag)
3935
}
4036

4137
override fun close() {
4238
if (!closed.compareAndSet(expect = false, update = true)) return
4339
httpClient.close()
4440
}
4541

46-
private suspend fun fetchHTTPWithPreferenceHandling(baseUrl: String, eTag: String): FetchResponse {
47-
var currentBaseUrl = baseUrl
42+
private suspend fun fetchHTTPWithPreferenceHandling(eTag: String): FetchResponse {
4843
repeat(3) {
49-
val response = fetchHTTP(currentBaseUrl, eTag)
44+
val response = fetchHTTP(baseUrl.value, eTag)
5045
val preferences = response.entry.config.preferences
5146
if (!response.isFetched ||
5247
response.entry.isEmpty() ||
5348
preferences == null ||
54-
preferences.baseUrl == currentBaseUrl
49+
preferences.baseUrl == baseUrl.value
5550
) {
5651
return response
5752
}
58-
if (isUrlCustom && preferences.redirect != RedirectMode.FORCE_REDIRECT.ordinal) return response
59-
currentBaseUrl = preferences.baseUrl
53+
if (isUrlCustom && preferences.redirect != RedirectMode.FORCE_REDIRECT.ordinal) {
54+
return response
55+
}
56+
57+
baseUrl.update { preferences.baseUrl }
58+
6059
if (preferences.redirect == RedirectMode.NO_REDIRECT.ordinal) {
6160
return response
6261
} else if (preferences.redirect == RedirectMode.SHOULD_REDIRECT.ordinal) {

src/commonTest/kotlin/com/configcat/DataGovernanceTests.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ class DataGovernanceTests {
138138

139139
assertEquals(1, mockEngine.requestHistory.size)
140140
assertTrue(mockEngine.requestHistory[0].url.toString().startsWith(customCdnUrl))
141+
142+
fetcher.fetch("")
143+
assertEquals(2, mockEngine.requestHistory.size)
144+
assertTrue(mockEngine.requestHistory[1].url.toString().startsWith(customCdnUrl))
141145
}
142146

143147
@Test

0 commit comments

Comments
 (0)