Hello. Does anybody know why ktor by default disab...
# announcements
Hello. Does anybody know why ktor by default disables okhttp redirects? https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-okhttp/jvm/src/io/ktor/client/engine/okhttp/OkHttpConfig.kt#L16 It is strange because okhttp enables redirects by default.
I assume its handled by ktor itself?
From docs:
By default, Ktor HTTP client does follow redirections; this feature allows to follow 
 redirects in a way that works with any HTTP engine.
Like Johannes said it probably handled in the ktor code instead of having to configure every engine to follow redirects in different ways. This means behaviour can be more consistent across engines and makes configuration easier.
Ok. I see that HttpRedirect feature is installed by default. But it breaks okhttp interceptors contract. If we have preconfigured okhttp client with interceptors, then Application Interceptors will be called twice but should be called once. https://square.github.io/okhttp/interceptors/
So if you have some kind of logging interceptor and only want log final responses without logging intermediate redirects it will not work with default ktor okhttp setup.
I think in your case you should go with either client:
if you chose one configure that one. Using ktor with OkHttp means you are using OkHttp as the engine only. Any features you want you should use the ktor ones. If ktor is missing features you want you can either build them yourself, see if someone else has built them or use a client that has those features (e.g. OkHttp) instead of ktor.
Sounds reasonable. Thanks.
👍 1