@@ -5,12 +5,12 @@ import io.ktor.http.isSuccess
55import io.ktor.util.reflect.TypeInfo
66import io.ktor.util.reflect.typeInfo
77
8- open class HttpResponse <T : Any >(val response : io.ktor.client.statement.HttpResponse , val provider : BodyProvider <T >) {
8+ open class HttpResponse <T >(val response : io.ktor.client.statement.HttpResponse , val provider : BodyProvider <T >) {
99 val status: Int = response.status.value
1010 val success: Boolean = response.status.isSuccess()
1111 val headers: Map <String , List <String >> = response.headers.mapEntries()
1212 suspend fun body (): T = provider.body(response)
13- suspend fun <V : Any > typedBody (type : TypeInfo ): V = provider.typedBody(response, type)
13+ suspend fun <V > typedBody (type : TypeInfo ): V = provider.typedBody(response, type)
1414
1515 companion object {
1616 private fun Headers.mapEntries (): Map <String , List <String >> {
@@ -21,31 +21,31 @@ open class HttpResponse<T : Any>(val response: io.ktor.client.statement.HttpResp
2121 }
2222}
2323
24- interface BodyProvider <T : Any > {
24+ interface BodyProvider <T > {
2525 suspend fun body (response : io.ktor.client.statement.HttpResponse ): T
26- suspend fun <V : Any > typedBody (response : io.ktor.client.statement.HttpResponse , type : TypeInfo ): V
26+ suspend fun <V > typedBody (response : io.ktor.client.statement.HttpResponse , type : TypeInfo ): V
2727}
2828
29- class TypedBodyProvider <T : Any >(private val type : TypeInfo ) : BodyProvider<T> {
29+ class TypedBodyProvider <T >(private val type : TypeInfo ) : BodyProvider<T> {
3030 @Suppress(" UNCHECKED_CAST" )
3131 override suspend fun body (response : io.ktor.client.statement.HttpResponse ): T =
3232 response.call.body(type) as T
3333
3434 @Suppress(" UNCHECKED_CAST" )
35- override suspend fun <V : Any > typedBody (response : io.ktor.client.statement.HttpResponse , type : TypeInfo ): V =
35+ override suspend fun <V > typedBody (response : io.ktor.client.statement.HttpResponse , type : TypeInfo ): V =
3636 response.call.body(type) as V
3737}
3838
39- class MappedBodyProvider <S : Any , T : Any >(private val provider : BodyProvider <S >, private val block : S .() -> T ) : BodyProvider<T> {
39+ class MappedBodyProvider <S , T >(private val provider : BodyProvider <S >, private val block : S .() -> T ) : BodyProvider<T> {
4040 override suspend fun body (response : io.ktor.client.statement.HttpResponse ): T =
4141 block(provider.body(response))
4242
43- override suspend fun <V : Any > typedBody (response : io.ktor.client.statement.HttpResponse , type : TypeInfo ): V =
43+ override suspend fun <V > typedBody (response : io.ktor.client.statement.HttpResponse , type : TypeInfo ): V =
4444 provider.typedBody(response, type)
4545}
4646
47- inline fun <reified T : Any > io.ktor.client.statement.HttpResponse.wrap (): HttpResponse <T > =
47+ inline fun <reified T > io.ktor.client.statement.HttpResponse.wrap (): HttpResponse <T > =
4848 HttpResponse (this , TypedBodyProvider (typeInfo<T >()))
4949
50- fun <T : Any , V : Any > HttpResponse<T>.map (block : T .() -> V ): HttpResponse <V > =
50+ fun <T , V > HttpResponse<T>.map (block : T .() -> V ): HttpResponse <V > =
5151 HttpResponse (response, MappedBodyProvider (provider, block))
0 commit comments