Updated on 2026-08-14
This commit is contained in:
parent
e10ff4c651
commit
87239cbf37
2 changed files with 41 additions and 9 deletions
|
|
@ -2,6 +2,7 @@ package com.tangem.datasource.utils
|
|||
|
||||
import android.os.Build
|
||||
import com.tangem.datasource.api.common.AuthProvider
|
||||
import com.tangem.datasource.utils.RequestHeader.CacheControlHeader.checkHeaderValueOrEmpty
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.version.AppVersionProvider
|
||||
import java.util.Locale
|
||||
|
|
@ -27,8 +28,24 @@ sealed class RequestHeader(vararg pairs: Pair<String, Provider<String>>) {
|
|||
class AppVersionPlatformHeaders(appVersionProvider: AppVersionProvider) : RequestHeader(
|
||||
"version" to Provider(appVersionProvider::versionName),
|
||||
"platform" to Provider { "android" },
|
||||
"language" to Provider { Locale.getDefault().language },
|
||||
"timezone" to Provider { TimeZone.getDefault().displayName },
|
||||
"device" to Provider { "${Build.MANUFACTURER} ${Build.MODEL}" },
|
||||
"language" to Provider { Locale.getDefault().language.checkHeaderValueOrEmpty() },
|
||||
"timezone" to Provider {
|
||||
TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT).checkHeaderValueOrEmpty()
|
||||
},
|
||||
"device" to Provider { "${Build.MANUFACTURER} ${Build.MODEL}".checkHeaderValueOrEmpty() },
|
||||
)
|
||||
|
||||
/**
|
||||
* Use it to avoid crash in okhttp headers
|
||||
*/
|
||||
fun String.checkHeaderValueOrEmpty(): String {
|
||||
for (i in this.indices) {
|
||||
val c = this[i]
|
||||
val charCondition = c == '\t' || c in '\u0020'..'\u007e'
|
||||
if (!charCondition) {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
|
@ -127,9 +127,11 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
"refcode" to Provider { EXPRESS_REF_CODE },
|
||||
"version" to Provider { VERSION_NAME },
|
||||
"platform" to Provider { "android" },
|
||||
"language" to Provider { Locale.getDefault().language },
|
||||
"timezone" to Provider { TimeZone.getDefault().displayName },
|
||||
"device" to Provider { "${Build.MANUFACTURER} ${Build.MODEL}" },
|
||||
"language" to Provider { Locale.getDefault().language.checkHeaderValueOrEmpty() },
|
||||
"timezone" to Provider {
|
||||
TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT).checkHeaderValueOrEmpty()
|
||||
},
|
||||
"device" to Provider { "${Build.MANUFACTURER} ${Build.MODEL}".checkHeaderValueOrEmpty() },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
@ -146,9 +148,11 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
"card_public_key" to Provider { APP_CARD_PUBLIC_KEY },
|
||||
"version" to Provider { VERSION_NAME },
|
||||
"platform" to Provider { "android" },
|
||||
"language" to Provider { Locale.getDefault().language },
|
||||
"timezone" to Provider { TimeZone.getDefault().displayName },
|
||||
"device" to Provider { "${Build.MANUFACTURER} ${Build.MODEL}" },
|
||||
"language" to Provider { Locale.getDefault().language.checkHeaderValueOrEmpty() },
|
||||
"timezone" to Provider {
|
||||
TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT).checkHeaderValueOrEmpty()
|
||||
},
|
||||
"device" to Provider { "${Build.MANUFACTURER} ${Build.MODEL}".checkHeaderValueOrEmpty() },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
@ -167,5 +171,16 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun String.checkHeaderValueOrEmpty(): String {
|
||||
for (i in this.indices) {
|
||||
val c = this[i]
|
||||
val charCondition = c == '\t' || c in '\u0020'..'\u007e'
|
||||
if (!charCondition) {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue