All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.retrofit.utils.RetrofitUtils.kt Maven / Gradle / Ivy

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