I am using HttpClient
from Ktor in my Kotlin project. How can I access the HTTP request headers? I know I can set them in the trailing HttpRequestBuilder
lambda, but how do I see the headers that are currently set for the request (ideally before sending it)?
You can a phase to client's HttpRequestPipeline
:
val phase = PipelinePhase("Headers check")
client.requestPipeline.addPhase(phase)
client.requestPipeline.intercept(phase) {
println("Headers: ${context.headers.entries()}")
}