is there a way to send a http request without accept header with ktor client? I need it in my test suite to check that its handled correctly
a
Aleksei Tirman [JB]
07/22/2021, 1:17 PM
You can do it with a little bit of magic πͺ by intercepting a request pipeline just after
Render
phase and removing
Accept
header:
Copy code
val client = HttpClient(Apache)
val newPhase = PipelinePhase("phase")
client.requestPipeline.insertPhaseAfter(HttpRequestPipeline.Render, newPhase)
client.requestPipeline.intercept(newPhase) {
context.headers.remove("Accept")
}
val r = client.get<String>("<https://httpbin.org/get>")
println(r)
π 1
c
christophsturm
07/22/2021, 1:33 PM
thank you. it is a totally valid usecase imo, sending requests that are not 100% wellformed is necessary to for testing, so maybe this can be made easier
π 1
ππ½ 1
h
Helio
07/19/2022, 2:02 AM
Does any of you know if this was improved or if this πͺ is still the best option for Ktor v2?
I thought an improvement was implemented at: https://github.com/ktorio/ktor/pull/1908/files but I canβt find any documentation about it in Ktor?