Home > Net >  Unresolved reference: responsePipeline in ktor
Unresolved reference: responsePipeline in ktor

Time:04-28

Hey I am working in ktor. I am following this enter image description here

CodePudding user response:

responsePipeline is a property of HttpClient class, and you are trying to access it on an instance of HttpClientConfig.

Lamda of HttpClient(OkHttp) returns an object of type HttpClientConfig which doesn't have a property named reponsePipeline.

To use responsePipeline you have to create an instance of HttpClient, and after that you can use it.

You can create a method which returns your configured httpClient

fun createHttpClient(config: HttpClientConfig<*>.() -> Unit): HttpClient {
    val httpClient = HttpClient(OkHttp) {
        config(this)
        install(Logging) {
            logger = Logger.SIMPLE
            level = LogLevel.BODY
        }
    }
    httpClient.responsePipeline.intercept(HttpResponsePipeline.Transform) {

    }
    return httpClient
}

Assign this to the actual definition.

actual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = createHttpClient(config)
  • Related