Handling URLs with non-ascii chars? #381
-
In the following code, the get fails:
The error is:
A browser has no problem with the example URL, and curl can also make an HTTP request with the example URL. It seems isahc either cannot handle internationalized domain names, or I'm doing something wrong? In a previous thread, I learned, that isahc uses the http crate's Uri module. I've tried asking http::uri to parse the example URI, and it also failes, seemingly due to a known problem: In hyperium/http#259 someone considers using the "url" create instead, but is that an option with isahc? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It appears that you are right, fn main() {
let domain = "sejs-svejbækbiler.dk";
let url = format!("https://{}/", idna::domain_to_ascii(domain).unwrap());
let response = isahc::get(url);
if let Err(e) = response {
println!("Error: {:?}", e);
}
} I agree that this is not an ideal experience and it should be handled better in the future, but this should work as a workaround for the current version. Ideally, this would be handled in the http crate upstream, perhaps as an optional feature. |
Beta Was this translation helpful? Give feedback.
It appears that you are right,
http::Uri
does not handle IDNA translation for domain names by itself, so you would need to do that manually first. You could do that with theidna
crate today:I agree that this is not an ideal experience and it should be handled better in the future, but this should work as a workaround for the current version. Ideally, this would be handled in the http crate upstream, perhaps as an optional feature.