Hey, guys. Does Ktor support punycode (googled a b...
# ktor
u
Hey, guys. Does Ktor support punycode (googled a bit but found nothing)? Looking for some util methods to convert ascii <-> unicode
b
Bit of a dense question, but what's puny code? 😄
u
https://en.wikipedia.org/wiki/Punycode domains written with national characters
👍 1
g
what kind support of punycode is required? Isn’t it designed to work using existing standards and do not require special support
u
So it does converting somewhere behind the scenes?
g
Ah, see, you just want to use util method
So it does converting somewhere behind the scenes?
I don’t think so. And why would ktor encode/decode it?
encoded punycode is real address, unicode representation just for humans and should be supported by browser only
u
let’s say i want to get url content of `президент.рф`(eg. send GET request to that url) . So i guess this should be supported, right?
g
okay, it’s more complicated, it should be supported by HTTP client
but where would you get such url? User input?
u
from browser app textbox, let’s say i’m working on a browser app
So i guess browser app should convert it into “xn-- ..” and pass to ktor
g
than it depend on your http client
u
and ktor (or underlying http client) should convert it to utf, right?
g
it should convert it to Punycode ascii from utf
u
ok, thanks for the explanation. But are you aware of any kind of `expect`ed methods in
common
in ktor that any particular http client provides as
actual
?
g
I don’t know any MPP implementation
u
ok, thanks anyway
g
I mean Ktor probably does nothing about Punycode, it delegates to platform http client
u
yup, i got it
g
anyway, if you implementing Browser, than you need a way to encode and decode Punycode, for example browsers has own set of rules what should be decoded and what shouldn’t to avoid fishing etc
u
that’s exactly what i’m looking for (though i don’t work on browser itself)
g
just port some existing implementation to Kotlin
u
yeah, before doing that i just wanted to find smth existing. BTW jvm provides it in
java.net.IDN
so it should not be a problem to implement it for native (what i originally needed) i guess
g
not be a problem to implement it for native
How Java implementation related to native?
u
one can write mpp implementation using java’s code as an example
and i need both java and native impl
for some mpp project
g
for Native I would just use some existing library probably
u
i’d love to find/adapt one or even mpp impl
g
one can write mpp implementation using java’s code as an example
Java delegates to native code. But there is also ICU4J implementation (which is used also for modern Android)
👍 1
y
The rules are non trivial if you want to implement it properly. e.g. not mixing different charsets, outside the valid combinations. It's probably best to find good implementation on each platform.
b
You would be better off writing a wrapper MPP library. For instance to have MPP json parser i could write an expect class in common module and then use say Gson for JVM and JS JSON for js as actual implementations.
This way you're free to use any platform-specific libraries for your MPP library