Hi, is there a good reason why the Ktor client tre...
# ktor
w
Hi, is there a good reason why the Ktor client treats
Url("")
as
Url("<http://localhost>")
? At least within the Ktor client context, wouldn’t it be better to enforce providing the full, absolute URL, including a hostname? When just constructing and combining relative URLs (e.g. in a 301 redirect) of course the hostname might be missing and that’s fine. But when sending a request, why would
localhost
ever be a good default? The current behavior causes quite a bit of confusion in our team because the Ktor client treats missing/incorrect configuration values as URLs against localhost which of course is not what anyone wanted.
👆 1
a
This a known issue with
UrlBuilder
. As far as I know, the default host and default protocol have been used to fill in the empty values while parsing incomplete URL strings. That decision was made long ago and cannot be easily reverted because the Ktor users already rely on this behavior.
w
Maybe in Ktor 4.0 it could be changed? Also, wouldn’t it be possible to make this behavior somewhat backwards compatible and just remember in the Url object whether the host is actually empty and then the Ktor client could check whether url.isComplete() or url.hasExplicitHost() or something like that
Then the only backwards incompatible change would be that requests would fail if no host is provided
The impact should be minimal in that case