Ktor (3.3.0) seems to (still) automatically add an...
# ktor
s
Ktor (3.3.0) seems to (still) automatically add an
Accept: */*
header to any request I send (that didn't contain an Accept header to start with). According to this old answer to this similar problem I'd have to disable all DefaultTransfermers. But that answer is from 2022. Is there a better solution with Ktor 3? Update: I found a workaround! With an OkHttp engine, i can add an interceptor to modify headers after ktor adds it's bonus headers.
Copy code
HttpClient(OkHttp) {
    install(HttpTimeout) {
        requestTimeoutMillis = timeout.inWholeMilliseconds
    }
    engine {
        addInterceptor { chain ->
            val original = chain.request()
            val filtered = original.newBuilder().apply {
                removeHeader(HttpHeaders.Accept)
            }.build()
            chain.proceed(filtered)
        }
    }
}
If you have a better solution, I'm all ears.
a
Unfortunately, there is no better solution than yours. Also, the Accept header can be overridden, but not removed.
s
by the way, I didn't came up with the workaround myself, I have to attribute it to Yuriy Kulikov in this old YouTrack-ticket. Funnily enough he answered right after me in the thread a year ago, but I didn't find his workaround until now 😂 I had another workaround before that (using CIO with specific config, which was also mentioned in the thread), but that only works for Accept-Charset, not for Accept. I prefer this workaround because it's more logical, but it isn't perfect, I found two headers so far which the interceptor apparently can't remove (Accept-Encoding & Connection). Luckily for me those two don't create issues in my particular case.