1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use hyper::Uri;
use hyper::error::UriError;
use std::str::FromStr;
pub fn url_join(url: &Uri, path: &str) -> Result<Uri, UriError> {
match (url.scheme(), url.authority(), url.path()) {
(Some(s), Some(a), p) => {
let mut curr_path = String::from(s);
curr_path += "://";
curr_path += a;
curr_path += p;
if !curr_path.ends_with('/') {
curr_path.push('/');
}
curr_path.push_str(path);
curr_path.parse::<Uri>()
},
_ => Uri::from_str("Failed to make a valid Url"),
}
}