Skip to content

Commit

Permalink
KTOR-3055 Add @ThreadLocal annotation to top level constants (#2586)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny-Gusev authored Aug 25, 2021
1 parent 380f86a commit 8097868
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.http.auth.*
import io.ktor.util.*
import kotlin.native.concurrent.*

/**
* Client authentication feature.
Expand Down Expand Up @@ -81,4 +82,5 @@ public fun HttpClientConfig<*>.Auth(block: Auth.() -> Unit) {
* be removed after that.
*/
@PublicAPICandidate("1.6.0")
@SharedImmutable
internal val AuthHeaderAttribute = AttributeKey<HttpAuthHeader>("AuthHeader")
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,26 @@ class AuthTest : ClientLoader() {
}
}

@Test
fun testRefreshOnBackgroundThread() = clientTests {
config {
install(Auth) {
bearer {
refreshTokens { BearerTokens("valid", "refresh") }
loadTokens { BearerTokens("invalid", "refresh") }
realm = "TestServer"
}
}
}

test { client ->
val response = withContext(Dispatchers.Default) {
client.get<HttpStatement>("$TEST_SERVER/auth/bearer/test-refresh").execute()
}
assertEquals(HttpStatusCode.OK, response.status)
}
}

@Suppress("JoinDeclarationAndAssignment")
@Test
fun testRefreshWithSameClient() = clientTests {
Expand Down
1 change: 1 addition & 0 deletions ktor-http/common/src/io/ktor/http/auth/HttpAuthHeader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlin.native.concurrent.*
@ThreadLocal
private val TOKEN_EXTRA = setOf('!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~')

@ThreadLocal
private val TOKEN68_EXTRA = setOf('-', '.', '_', '~', '+', '/')

@ThreadLocal
Expand Down

0 comments on commit 8097868

Please sign in to comment.