I would like to retry HTTPS requests with HTTP req...
# ktor
t
I would like to retry HTTPS requests with HTTP requests if there is a
ConnectException
. Is the code below correct or is there a better way to do this?
Copy code
client.install("HttpsToHttp") {
    requestPipeline.intercept(HttpRequestPipeline.Before) {
        val requestBuilder = this.context
        try {
            proceedWith(it)
        } catch (exception: ConnectException) {
            if (requestBuilder.url.protocol == URLProtocol.HTTPS) {
                requestBuilder.url.protocol = URLProtocol.HTTP
                proceedWith(requestPipeline.execute(requestBuilder, it)) // not sure if this is correct
            } else {
                throw exception
            }
        }
    }
}
Posted in #ktor
👀 1