is there a way to send a http request without acce...
# ktor
c
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
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
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
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?