Closed JulianKnodt closed 1 year ago
Not sure what you mean by converting back? You can always build a new URL. But maybe you want something else?
use url;
use url::Url;
fn main() {
let url = Url::parse("http://hostname:123/").unwrap();
println!("{:?}", url);
let new_url = "https://".to_owned() + &url.host().unwrap().to_string();
let new_url = Url::parse(&new_url).unwrap();
println!("{:?}", new_url);
}
hmmmm specifically I'm thinking about the use case of
converting https://www.foo.com/a/b/c/d
to https://www.foo.com/
.
I reread the docs ad noticed I can do this with .path_segments_mut().clear()
, but maybe it's worth adding an explicit note to path_segments_mut()
?
The reason I asked this question is because I expected a method that explicitly drops all path segments, and I equated it in my mind with .host()
.
You would probably also want to clear the query string and fragment in that case.
I was wondering if there's anyway to convert from a
Host
back to aURL
after callingurl.host()
? I realize this is probably under-specified, since there is no longer a scheme, so I was further wondering if there would be a. way to convert anOrigin
to aURL
? After browsing through the docs & open GH issues, I didn't see any question about this, so was wondering if it made sense to add such a thing?