[HTTP API] URLs with underscores in the domain name are rejected as malformed
Kimapr opened this issue ยท 3 comments
Minecraft Version
1.16.x
Version
1.98.2
Details
In my setup i use hostnames in /etc/hosts with underscores in them, and CC rejects URLs with them even though they are perfectly valid.
lua> http.get("http://kdp_portable/")
nil
"URL malformed"
Right, this is because kdp_portable
is an invalid hostname - they can only contain alpha-numeric characters and .
(see RFC 952).
jshell> import java.net.URI;
jshell> var uri = new URI("http://kdp_portable/")
uri ==> http://kdp_portable/
jshell> uri.getHost()
$3 ==> null
jshell> uri.getAuthority()
$4 ==> "kdp_portable"
I guess what one could do is parse the authority, strip out the user and port information. Though Not Ideal, and something I'd rather avoid doing.
Right, this is because kdp_portable is an invalid hostname - they can only contain alpha-numeric characters and . (see RFC 952).
But it works in any other application, so why won't it work in computercraft too?
Because nobody follows internet standards very thoroughly. Apart from the Java stdlib apparently.
Edit: Apparently the more recent RFC 3986 does allow for more flexible host names, but given there's been an open issue since 2013 to add this to the JDK, I can't imagine it's going to be fixed any time soon. For now, it's probably worth just using hyphens.