lemonlabsuk / scala-uri

Simple scala library for building and parsing URIs
Other
305 stars 34 forks source link

Question: Support for IDNs as punycode #26

Closed x4121 closed 5 years ago

x4121 commented 5 years ago

Hi, thanks for all the work on this library, it's been a big help so far.

The only "issue" I'm currently facing are internationalized domain names (or at least their representation in ASCII as punycode (RFC 3492)).

The problem is that domains have to be encoded in punycode, while the path has to be urlencoded, for most HTTP clients to work. There are libraries that can convert IDNs to punycode, but need the separate domain. scala-uri can separate domain from a URL, but doesn't convert the domain to punycode itself.

The workaround is short, but feels wrong/ugly:

import java.net.IDN

val url = UrlParser.parseAbsoluteUrl("https://はじめよう.みんな/howto.html").get
val punycodeUrl = url.withHost(IDN.toASCII(url.host.toString))

Are there plans to support conversion to punycode in scala-uri itself?

theon commented 5 years ago

So sorry for the delay getting back to you!

Would adding a toStringPunyCode method meet your needs?

x4121 commented 5 years ago

I think that would be a nice feature (without having to implement all of the content in RFC 3987 ( Internationalized Resource Identifiers (IRIs)))

theon commented 5 years ago

I have released this as version 1.4.1.

See: 07756b8 and https://github.com/lemonlabsuk/scala-uri#punycode

x4121 commented 5 years ago

Nice, thank you :slightly_smiling_face: