-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/AND-87_WC_library_update
- Loading branch information
Showing
38 changed files
with
132 additions
and
32,481 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
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/concordium/wallet/data/backend/InMemoryCookieJar.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,52 @@ | ||
package com.concordium.wallet.data.backend | ||
|
||
import okhttp3.Cookie | ||
import okhttp3.CookieJar | ||
import okhttp3.HttpUrl | ||
|
||
/** | ||
* A simple [CookieJar] which stores the cookies in the memory, without a persistence. | ||
*/ | ||
class InMemoryCookieJar : CookieJar { | ||
private val cookieSet = mutableSetOf<StoredCookie>() | ||
|
||
override fun loadForRequest(url: HttpUrl): List<Cookie> = synchronized(this) { | ||
cookieSet.removeAll(StoredCookie::isExpired) | ||
return@synchronized cookieSet.mapNotNull { it.takeIf { it.matches(url) }?.cookie } | ||
} | ||
|
||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) { | ||
synchronized(this) { | ||
cookies.mapTo(cookieSet, ::StoredCookie) | ||
} | ||
} | ||
|
||
private class StoredCookie(val cookie: Cookie) { | ||
val isExpired: Boolean | ||
get() = cookie.expiresAt < System.currentTimeMillis() | ||
|
||
fun matches(url: HttpUrl) = | ||
cookie.matches(url) | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is StoredCookie) return false | ||
|
||
return this.cookie.name == other.cookie.name | ||
&& this.cookie.domain == other.cookie.domain | ||
&& this.cookie.path == other.cookie.path | ||
&& this.cookie.secure == other.cookie.secure | ||
&& this.cookie.hostOnly == other.cookie.hostOnly | ||
} | ||
|
||
override fun hashCode(): Int = with(cookie) { | ||
var result = 17 | ||
result = 31 * result + name.hashCode() | ||
result = 31 * result + domain.hashCode() | ||
result = 31 * result + path.hashCode() | ||
result = 31 * result + secure.hashCode() | ||
result = 31 * result + hostOnly.hashCode() | ||
return result | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.