-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http) add TokenMessageAuthorizationHeader
- Loading branch information
1 parent
cbfbdb5
commit c43e4aa
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...olkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/context/TokenMessageHeaders.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import kotlin.coroutines.AbstractCoroutineContextElement | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.coroutineContext | ||
|
||
/** | ||
* Contains context about the current token message header | ||
*/ | ||
data class TokenMessageAuthorizationHeader( | ||
val token: String? = null | ||
) : AbstractCoroutineContextElement(TokenMessageAuthorizationHeader) { | ||
companion object Key : CoroutineContext.Key<TokenMessageAuthorizationHeader> | ||
} | ||
|
||
/** | ||
* Retrieves TokenMessageAuthorizationHeader in the current coroutine if it is found. | ||
*/ | ||
suspend fun currentTokenMessageAuthorizationHeadersOrNull(): TokenMessageAuthorizationHeader? = | ||
coroutineContext[TokenMessageAuthorizationHeader] | ||
|
||
/** | ||
* Retrieves TokenMessageAuthorizationHeader in the current coroutine, and throws IllegalStateException | ||
* if it could not be found. | ||
*/ | ||
suspend fun currentTokenMessageAuthorizationHeaders(): TokenMessageAuthorizationHeader = | ||
coroutineContext[TokenMessageAuthorizationHeader] | ||
?: throw IllegalStateException("No TokenMessageAuthorizationHeader object in current coroutine context") |