Skip to content

Commit b14c6d4

Browse files
committed
downgrade ktor to 1.6.8
1 parent 4a80c46 commit b14c6d4

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ kotlin {
218218

219219
sourceSets {
220220
val serializationVersion = "1.3.2"
221-
val ktorVersion = "2.0.0-beta-1"
221+
val ktorVersion = "1.6.8"
222222
val korlibsVersion = "2.2.0"
223223
val sparkVersion = "2.9.3"
224224
val androidSpotifyAuthVersion = "1.2.5"

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyApiBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.adamratzman.spotify.models.serialization.nonstrictJson
99
import com.adamratzman.spotify.models.serialization.toObject
1010
import com.adamratzman.spotify.utils.urlEncodeBase64String
1111
import com.soywiz.krypto.SHA256
12-
import io.ktor.client.plugins.ServerResponseException
12+
import io.ktor.client.features.ServerResponseException
1313
import io.ktor.utils.io.core.toByteArray
1414
import kotlinx.coroutines.CancellationException
1515
import kotlinx.serialization.json.Json

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyExceptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.adamratzman.spotify
33

44
import com.adamratzman.spotify.models.AuthenticationError
55
import com.adamratzman.spotify.models.ErrorObject
6-
import io.ktor.client.plugins.ResponseException
6+
import io.ktor.client.features.ResponseException
77

88
public sealed class SpotifyException(message: String, cause: Throwable? = null) : Exception(message, cause) {
99
public abstract class UnNullableException(message: String) : SpotifyException(message)

src/commonMain/kotlin/com.adamratzman.spotify/http/HttpConnection.kt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import com.adamratzman.spotify.models.ErrorResponse
1111
import com.adamratzman.spotify.models.SpotifyRatelimitedException
1212
import com.adamratzman.spotify.models.serialization.nonstrictJson
1313
import com.adamratzman.spotify.models.serialization.toObject
14+
import com.soywiz.korio.dynamic.KDynamic.Companion.toLong
1415
import io.ktor.client.HttpClient
15-
import io.ktor.client.plugins.ResponseException
16+
import io.ktor.client.features.ResponseException
1617
import io.ktor.client.request.HttpRequestBuilder
1718
import io.ktor.client.request.header
1819
import io.ktor.client.request.request
19-
import io.ktor.client.request.setBody
2020
import io.ktor.client.request.url
21-
import io.ktor.client.statement.bodyAsText
21+
import io.ktor.client.statement.readText
2222
import io.ktor.http.ContentType
2323
import io.ktor.http.HttpMethod
2424
import io.ktor.http.content.ByteArrayContent
@@ -62,21 +62,19 @@ public class HttpConnection constructor(
6262
url(this@HttpConnection.url)
6363
method = this@HttpConnection.method.externalMethod
6464

65-
setBody(
66-
when (this@HttpConnection.method) {
67-
HttpRequestMethod.DELETE -> {
68-
bodyString.toByteArrayContent() ?: body
69-
}
70-
HttpRequestMethod.PUT, HttpRequestMethod.POST -> {
71-
val contentString = if (contentType == ContentType.Application.FormUrlEncoded) {
72-
bodyMap?.map { "${it.key}=${it.value}" }?.joinToString("&") ?: bodyString
73-
} else bodyString
65+
body = when (this@HttpConnection.method) {
66+
HttpRequestMethod.DELETE -> {
67+
bodyString.toByteArrayContent() ?: body
68+
}
69+
HttpRequestMethod.PUT, HttpRequestMethod.POST -> {
70+
val contentString = if (contentType == ContentType.Application.FormUrlEncoded) {
71+
bodyMap?.map { "${it.key}=${it.value}" }?.joinToString("&") ?: bodyString
72+
} else bodyString
7473

75-
contentString.toByteArrayContent() ?: ByteArrayContent("".toByteArray(), contentType)
76-
}
77-
else -> body
74+
contentString.toByteArrayContent() ?: ByteArrayContent("".toByteArray(), contentType)
7875
}
79-
)
76+
else -> body
77+
}
8078

8179
// let additionalHeaders overwrite headers
8280
val allHeaders = if (additionalHeaders == null) this@HttpConnection.headers
@@ -94,7 +92,7 @@ public class HttpConnection constructor(
9492
val httpRequest = buildRequest(additionalHeaders)
9593
if (api?.spotifyApiOptions?.enableDebugMode == true) println("DEBUG MODE: Request: $this")
9694
try {
97-
return httpClient.request(httpRequest).let { response ->
95+
return httpClient.request<io.ktor.client.statement.HttpResponse>(httpRequest).let { response ->
9896
val respCode = response.status.value
9997

10098
if (respCode in 500..599 && (retryIfInternalServerErrorLeft == null || retryIfInternalServerErrorLeft == -1 || retryIfInternalServerErrorLeft > 0)) {
@@ -118,7 +116,7 @@ public class HttpConnection constructor(
118116
} else throw SpotifyRatelimitedException(ratelimit)
119117
}
120118

121-
val body: String = response.bodyAsText()
119+
val body: String = response.readText()
122120
if (api?.spotifyApiOptions?.enableDebugMode == true) println("DEBUG MODE: $body")
123121

124122
if (respCode == 401 && body.contains("access token") && api?.spotifyApiOptions?.automaticRefresh == true) {
@@ -147,7 +145,7 @@ public class HttpConnection constructor(
147145
} catch (e: CancellationException) {
148146
throw e
149147
} catch (e: ResponseException) {
150-
val errorBody = e.response.bodyAsText()
148+
val errorBody = e.response.readText()
151149
if (api?.spotifyApiOptions?.enableDebugMode == true) println("DEBUG MODE: $errorBody")
152150
try {
153151
val respCode = e.response.status.value

0 commit comments

Comments
 (0)