Skip to content

Use url::Url instead of http::Uri #382

@troelsarvin

Description

@troelsarvin

isahc's reliance on http::Uri makes it cumbersome to work with URLs which have hostnames with non-ASCII characters.
I suggest that isahc switch to using url::Url instead of http::Uri.

Motivations:

  • In 2022, it should be straight forward to work with URLs which are international.
  • Also, sematically, I claim it is more clear for an HTTP client to work with URLs rather than URIs. It's hard to imagine isahc being used with non-URL URIs.

The following code shows the current state of affairs in some crates:

/*
    In Carto.toml:

[dependencies]
url = "2"
http = "0.2"
reqwest = "0.11"

*/

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let url_str = "https://www.fc-højvang.dk/";

                                                    // Crate: url
    let url = url::Url::parse(url_str)?;            //
    println!("url: {}", url);                       // Prints URL with IDNA

                                                    // Crate: reqwest
    let reqwest_url = reqwest::Url::parse(url_str)?;//
    println!("reqwest_uri: {}", reqwest_url);       // Prints URL with IDNA

                                                    // Crate: http
    let http_uri = url_str.parse::<http::Uri>()?;   //
    println!("http_uri: {}", http_uri);             // FAILS
    /*
      Error message:
      InvalidUri(InvalidUriChar)
    */

    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingRequires breaking backwards compatibility

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions