-
Notifications
You must be signed in to change notification settings - Fork 13
Add User-Agent field #158
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
base: main
Are you sure you want to change the base?
Add User-Agent field #158
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must check if can extract version string from
SDK_INT
I think including Build.VERSION
and Build.RELEASE_OR_CODENAME
should be enough here.
@@ -449,6 +469,8 @@ internal class SyncStream( | |||
} | |||
} | |||
|
|||
internal expect fun getOS(): String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this to be in a separate file (e.g. utils/OSInfo.kt
).
@@ -172,7 +190,7 @@ internal class SyncStream( | |||
contentType(ContentType.Application.Json) | |||
headers { | |||
append(HttpHeaders.Authorization, "Token ${credentials.token}") | |||
append("User-Id", credentials.userId ?: "") | |||
append("User-Agent", powerSyncUserAgent()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we're doing this on all requests, a better place to put this may be in init
:
fun HttpClientConfig<*>.configureClient() {
install(HttpTimeout)
install(ContentNegotiation)
defaultRequest {
headers {
append("User-Agent", $LIBRARY_NAME/$LIBRARY_VERSION ${getOS()}")
}
}
}
// TODO: Swift SDK relies on this too. | ||
// Find out how to add a build flag to toggle between "powersync-kotlin" and "powersync-swift". | ||
buildConfigField(STRING, "LIBRARY_NAME", "powersync-kotlin") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't have to worry about this. We'll likely add an API for clients to add their own headers in the future. The Swift SDK could use that to always override the User-Agent
header if necessary. So it should be fine if this always reports powersync-kotlin
for now.
Adds User-Agent in similar fashion to Dart and JS repos.
Based on abandoned pull #57
Todos
android $base/$version
withandroid <SDK_INT or OS version>
- must check if can extract version string fromSDK_INT