servo / rust-url

URL parser for Rust
https://docs.rs/url/
Apache License 2.0
1.27k stars 318 forks source link

Optional API to convert to http::Uri #824

Open Redfire75369 opened 1 year ago

Redfire75369 commented 1 year ago

Rationale

The simplest way to convert from a url::Url to a http::Uri currently is to turn it into a string and then parse it again. It would be helpful if there was an API to do this conversion directly, instead of necessitating another round of parsing

Proposal

With a feature flag called http, the dependency http can be added. When the http feature is active, a function can be exposed which does the conversion from url's internal structure to that of http::Uri's.

valenting commented 1 year ago

I'm not totally convinced this is something that belongs in the url crate. I'd rather keep dependencies to a minimal, and even if this is behind a feature gate, it still needs CI testing. I would suggest a crate that depends on both rust-url and http that uses Builder to create a new http uri from parts.

Redfire75369 commented 1 year ago

I understand your concerns, perhaps a Builder API for this crate may be more helpful then, so that the conversion could be done both ways relatively efficiently.

Kinrany commented 10 months ago

Are URIs truly deprecated in some sense? The URL standard by WHATWG claims that a single algorithm is used for both and that they aim to deprecate URIs as a term in favor of URL, but I don't quite get how that could be possible when URIs are a superset of URLs.