Skip to content
Merged
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
4 changes: 4 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
{
"type": "generic",
"path": "build.gradle.kts"
},
{
"type": "generic",
"path": "src/main/kotlin/com/workos/android/internal/Transport.kt"
}
]
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/com/workos/android/internal/Transport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ private const val BACKOFF_MULTIPLIER = 2.0
private const val MAX_DELAY_MS = 8_000L
private const val JITTER_FACTOR = 0.5

// Stamped by release-please on every release (see release-please-config.json);
// must stay on one line with the marker comment or it stops being updated.
private const val VERSION = "0.2.1" // x-release-please-version

/**
* Mirrors the other WorkOS SDKs' `WorkOS <platform>/<version>` shape, which the
* data platform parses with an end-anchored regex — nothing may follow the version.
*/
private const val USER_AGENT = "WorkOS Android/$VERSION"

/** A fully-read HTTP exchange. Read before any error decision so the body is available. */
private class RawResponse(
val code: Int,
Expand Down Expand Up @@ -113,6 +123,7 @@ public class Transport(
.method(method, requestBody)
.header("Authorization", "Bearer " + configuration.apiKey)
.header("Content-Type", "application/json")
.header("User-Agent", USER_AGENT)
if (idempotencyKey != null) builder.header("Idempotency-Key", idempotencyKey)
val extra = options?.headers
if (extra != null) {
Expand Down
13 changes: 13 additions & 0 deletions src/test/kotlin/com/workos/android/TransportBehaviorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ class TransportBehaviorTest {
assertEquals("Bearer sk_test_123", server.awaitRequest().headerValue("Authorization"))
}

@Test
fun `sends a WorkOS Android user agent ending in the version`() =
runTest {
val (c, server) = testClient(responding = """{"data":[],"list_metadata":{}}""")

c.organizations.list()

val userAgent = server.awaitRequest().headerValue("User-Agent")
assertNotNull(userAgent)
// End-anchored like the data platform's SDK-attribution regexes.
assertTrue(userAgent.matches(Regex("""WorkOS Android/[^\s]+""")), "unexpected User-Agent: $userAgent")
}

@Test
fun `retries a 500 and then succeeds`() =
runTest {
Expand Down
Loading