https://kotlinlang.org logo
#ktor
Title
# ktor
h

Hexa

03/29/2022, 10:41 PM
Anyone got example of intercepting outgoing Http client request before it is sent out?
a

Aleksei Tirman [JB]

03/30/2022, 8:54 AM
Here it is:
Copy code
import io.ktor.client.HttpClient
import io.ktor.client.engine.apache.*
import io.ktor.client.request.*
import io.ktor.client.statement.*

suspend fun main() {
    val client = HttpClient(Apache)
    client.sendPipeline.intercept(HttpSendPipeline.Before) {
        println(context.url.encodedPath)
    }

    client.get<HttpResponse>("<https://httpbin.org/get>")
}
👍 1
3 Views