
jvmMain.retrofit.utils.RetrofitUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of network-response-jvm Show documentation
Show all versions of network-response-jvm Show documentation
NetworkResponse multiplatform
The newest version!
@file:Suppress("SpreadOperator")
package com.javiersc.resources.networkResponse.retrofit.utils
import com.javiersc.resources.networkResponse.ktor.toHttpStatusCode
import io.ktor.http.Headers
import io.ktor.http.HttpStatusCode
import io.ktor.http.headersOf
import retrofit2.HttpException
import retrofit2.Response
internal val HttpException.httpStatusCode: HttpStatusCode get() = code() toHttpStatusCode message()
internal val Response<*>.httpStatusCode: HttpStatusCode get() = code() toHttpStatusCode message()
internal val HttpException.headers: Headers get() = headersOf(*response()?.headers().toOkHttpHeaders())
internal val Response<*>.headers: Headers get() = headersOf(*headers().toOkHttpHeaders())
private fun okhttp3.Headers?.toOkHttpHeaders(): Array>> {
return this?.toMultimap()?.map { header -> header.key to header.value }
?.toTypedArray()
?: arrayOf("Content-Length" to listOf("0"))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy