diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-26 16:30:51 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-26 16:30:51 -0600 |
commit | e369918a12347884898d7c3e9bebf92731db55d5 (patch) | |
tree | 89fde7b7db1692c4c0b04d3df0593374710ca1bd /shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client | |
parent | b4785c42aa026a561674257955a7c59b8c964e6f (diff) | |
download | etbsa-trackermap-mobile-e369918a12347884898d7c3e9bebf92731db55d5.tar.gz etbsa-trackermap-mobile-e369918a12347884898d7c3e9bebf92731db55d5.tar.bz2 etbsa-trackermap-mobile-e369918a12347884898d7c3e9bebf92731db55d5.zip |
Disabled automatic storage of cookies in iOS engine (https://youtrack.jetbrains.com/issue/KTOR-3748), so we can handle them manually.
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client')
4 files changed, 19 insertions, 20 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt index a5a893e..6d9dbea 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt @@ -11,13 +11,9 @@ */ package mx.trackermap.TrackerMap.client.apis -import com.russhwolf.settings.Settings import mx.trackermap.TrackerMap.client.models.User import mx.trackermap.TrackerMap.client.infrastructure.* -const val SERVER_URL_KEY = "server_url" -const val ACCESS_TOKEN_KEY = "access_token" - class SessionApi(sessionManager: SessionManager) : ApiClient(sessionManager) { /** @@ -36,8 +32,7 @@ class SessionApi(sessionManager: SessionManager) : ApiClient(sessionManager) { return when (response.responseType) { ResponseType.Success -> { - val settings = Settings() - settings.remove(ACCESS_TOKEN_KEY) + sessionManager.clearSession() } ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() @@ -102,14 +97,13 @@ class SessionApi(sessionManager: SessionManager) : ApiClient(sessionManager) { return when (response.responseType) { ResponseType.Success -> { + print("Response headers = ${response.headers.values}\n") val cookie = response.headers .values .flatten() .find { it.contains("JSESSIONID") }!! .replace("; Path=/", "") this.sessionManager.token = cookie - val settings = Settings() - settings.putString(ACCESS_TOKEN_KEY, cookie) (response as Success<*>).data as User } ResponseType.Informational -> TODO() diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt index 385ece4..78bcf3b 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt @@ -17,7 +17,6 @@ */ package mx.trackermap.TrackerMap.client.infrastructure -import com.russhwolf.settings.Settings import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.features.* @@ -32,8 +31,6 @@ import io.ktor.client.request.forms.FormDataContent import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.util.* -import mx.trackermap.TrackerMap.client.apis.ACCESS_TOKEN_KEY -import mx.trackermap.TrackerMap.client.apis.SERVER_URL_KEY import kotlinx.serialization.json.Json as KotlinJson open class ApiClient( @@ -47,7 +44,7 @@ open class ApiClient( protected const val ApiFormURLType = "application/x-www-form-urlencoded" protected const val ApiXmlMediaType = "application/xml" - val client: HttpClient = HttpClient { + val client: HttpClient = HttpClientProvider().getHttpClient().config { install(HttpTimeout) { connectTimeoutMillis = 20_000 requestTimeoutMillis = 20_000 @@ -71,12 +68,6 @@ open class ApiClient( ApiContentType to ApiJsonMediaType, ApiAccept to ApiJsonMediaType ) - - val jsonHeaders: Map<String, String> = - mapOf( - ApiContentType to ApiJsonMediaType, - ApiAccept to ApiJsonMediaType - ) } protected inline fun <reified T> fillRequest( diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt new file mode 100644 index 0000000..873722f --- /dev/null +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt @@ -0,0 +1,7 @@ +package mx.trackermap.TrackerMap.client.infrastructure + +import io.ktor.client.* + +expect class HttpClientProvider() { + fun getHttpClient(): HttpClient +}
\ No newline at end of file diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt index 306533c..6287b0c 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt @@ -3,13 +3,16 @@ package mx.trackermap.TrackerMap.client.infrastructure import com.russhwolf.settings.Settings import com.russhwolf.settings.get import com.russhwolf.settings.set -import mx.trackermap.TrackerMap.client.apis.ACCESS_TOKEN_KEY -import mx.trackermap.TrackerMap.client.apis.SERVER_URL_KEY class SessionManager( private val defaultBaseUrl: String ) { + companion object { + const val SERVER_URL_KEY = "server_url" + const val ACCESS_TOKEN_KEY = "access_token" + } + private val settings = Settings() var baseUrl: String @@ -24,4 +27,8 @@ class SessionManager( settings[ACCESS_TOKEN_KEY] = token } + fun clearSession() { + settings.remove(ACCESS_TOKEN_KEY) + settings.remove(SERVER_URL_KEY) + } }
\ No newline at end of file |