@@ -11,14 +11,14 @@ import com.adamratzman.spotify.models.ErrorResponse
1111import com.adamratzman.spotify.models.SpotifyRatelimitedException
1212import com.adamratzman.spotify.models.serialization.nonstrictJson
1313import com.adamratzman.spotify.models.serialization.toObject
14+ import com.soywiz.korio.dynamic.KDynamic.Companion.toLong
1415import io.ktor.client.HttpClient
15- import io.ktor.client.plugins .ResponseException
16+ import io.ktor.client.features .ResponseException
1617import io.ktor.client.request.HttpRequestBuilder
1718import io.ktor.client.request.header
1819import io.ktor.client.request.request
19- import io.ktor.client.request.setBody
2020import io.ktor.client.request.url
21- import io.ktor.client.statement.bodyAsText
21+ import io.ktor.client.statement.readText
2222import io.ktor.http.ContentType
2323import io.ktor.http.HttpMethod
2424import 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