Skip to content

Commit d75214c

Browse files
authored
Merge pull request #927 from supabase-community/os-version
Add new standard headers
2 parents 0f907ea + 48ac644 commit d75214c

File tree

18 files changed

+204
-6
lines changed

18 files changed

+204
-6
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.github.jan.supabase
2+
3+
internal actual fun getOSInformation(): OSInformation? = OSInformation(
4+
name = "Android",
5+
version = android.os.Build.VERSION.RELEASE
6+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.supabase.supabase
2+
3+
import kotlinx.cinterop.ExperimentalForeignApi
4+
import kotlinx.cinterop.UnsafeNumber
5+
import kotlinx.cinterop.useContents
6+
7+
@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
8+
internal fun getOSVersion(): String {
9+
val processInfo = platform.Foundation.NSProcessInfo.processInfo
10+
return processInfo.operatingSystemVersion.useContents {
11+
val majorVersion = this.majorVersion
12+
val minorVersion = this.minorVersion
13+
val patchVersion = this.patchVersion
14+
buildString {
15+
append(majorVersion)
16+
append(".")
17+
append(minorVersion)
18+
append(".")
19+
append(patchVersion)
20+
}
21+
}
22+
}
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
@file:Suppress("UndocumentedPublicProperty")
22
package io.github.jan.supabase
33

4+
import io.github.jan.supabase.logging.e
5+
46
/**
57
* Represents a target platform
68
*/
79
enum class PlatformTarget {
810
JVM, ANDROID, JS, WASM_JS, IOS, WINDOWS, MACOS, TVOS, WATCHOS, LINUX;
911
}
1012

13+
data class OSInformation(
14+
val name: String,
15+
val version: String
16+
) {
17+
18+
companion object {
19+
val CURRENT by lazy {
20+
try {
21+
getOSInformation()
22+
} catch (e: Exception) {
23+
SupabaseClient.LOGGER.e(e) {
24+
"Failed to get OS information, please report this issue"
25+
}
26+
null
27+
}
28+
}
29+
}
30+
31+
}
32+
1133
/**
1234
* The current target platform
1335
*/
14-
expect val CurrentPlatformTarget: PlatformTarget
36+
expect val CurrentPlatformTarget: PlatformTarget
37+
38+
/**
39+
* The current operating system information
40+
*/
41+
internal expect fun getOSInformation(): OSInformation?

Supabase/src/commonMain/kotlin/io/github/jan/supabase/SupabaseClient.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ internal class SupabaseClientImpl(
119119
supabaseKey,
120120
config.networkConfig.httpConfigOverrides,
121121
config.networkConfig.requestTimeout.inWholeMilliseconds,
122-
config.networkConfig.httpEngine
122+
config.networkConfig.httpEngine,
123+
config.osInformation
123124
)
124125

125126
override val pluginManager = PluginManager(config.plugins.toList().associate { (key, value) ->

Supabase/src/commonMain/kotlin/io/github/jan/supabase/SupabaseClientBuilder.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class SupabaseClientBuilder @PublishedApi internal constructor(private val supab
9090
*/
9191
var accessToken: AccessTokenProvider? = null
9292

93+
/**
94+
* The current operating system information.
95+
*/
96+
var osInformation: OSInformation? = OSInformation.CURRENT
97+
9398
private val httpConfigOverrides = mutableListOf<HttpConfigOverride>()
9499
private val plugins = mutableMapOf<String, PluginProvider>()
95100

@@ -124,7 +129,8 @@ class SupabaseClientBuilder @PublishedApi internal constructor(private val supab
124129
defaultSerializer = defaultSerializer,
125130
coroutineDispatcher = coroutineDispatcher,
126131
accessToken = accessToken,
127-
plugins = plugins
132+
plugins = plugins,
133+
osInformation = osInformation
128134
)
129135
return SupabaseClientImpl(
130136
config

Supabase/src/commonMain/kotlin/io/github/jan/supabase/SupabaseClientConfig.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ internal data class SupabaseClientConfig(
1313
val defaultSerializer: SupabaseSerializer,
1414
val coroutineDispatcher: CoroutineDispatcher,
1515
val accessToken: AccessTokenProvider?,
16-
val plugins: Map<String, PluginProvider>
16+
val plugins: Map<String, PluginProvider>,
17+
val osInformation: OSInformation?
1718
)
1819

1920
internal data class SupabaseNetworkConfig(

Supabase/src/commonMain/kotlin/io/github/jan/supabase/network/KtorSupabaseHttpClient.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package io.github.jan.supabase.network
33

44
import io.github.jan.supabase.BuildConfig
5+
import io.github.jan.supabase.OSInformation
56
import io.github.jan.supabase.SupabaseClient
67
import io.github.jan.supabase.annotations.SupabaseInternal
78
import io.github.jan.supabase.exceptions.HttpRequestException
@@ -42,7 +43,8 @@ class KtorSupabaseHttpClient @SupabaseInternal constructor(
4243
private val supabaseKey: String,
4344
modifiers: List<HttpClientConfig<*>.() -> Unit> = listOf(),
4445
private val requestTimeout: Long,
45-
engine: HttpClientEngine? = null
46+
engine: HttpClientEngine? = null,
47+
private val osInformation: OSInformation?
4648
): SupabaseHttpClient() {
4749

4850
init {
@@ -111,6 +113,10 @@ class KtorSupabaseHttpClient @SupabaseInternal constructor(
111113
append("apikey", supabaseKey)
112114
}
113115
append("X-Client-Info", "supabase-kt/${BuildConfig.PROJECT_VERSION}")
116+
osInformation?.let {
117+
append("X-Supabase-Client-Platform", it.name)
118+
append("X-Supabase-Client-Platform-Version", it.version)
119+
}
114120
}
115121
port = HTTPS_PORT
116122
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.jan.supabase
2+
3+
import io.supabase.supabase.getOSVersion
4+
5+
internal actual fun getOSInformation(): OSInformation? = OSInformation(
6+
name = "iOS",
7+
version = getOSVersion()
8+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package io.github.jan.supabase
2+
3+
internal actual fun getOSInformation(): OSInformation? = null
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.github.jan.supabase
2+
3+
internal actual fun getOSInformation(): OSInformation? = OSInformation(
4+
name = System.getProperty("os.name"),
5+
version = System.getProperty("os.version")
6+
)

0 commit comments

Comments
 (0)