Refactor url handling

This commit is contained in:
Dominik Werder
2023-12-07 22:35:13 +01:00
parent 90fe23b676
commit 44e37c7dbc
14 changed files with 71 additions and 57 deletions

View File

@@ -18,6 +18,7 @@ use err::Error;
use futures_util::Stream;
use futures_util::StreamExt;
use http::Request;
use http::Uri;
use range::evrange::NanoRange;
use range::evrange::PulseRange;
use range::evrange::SeriesRange;
@@ -3188,3 +3189,15 @@ impl ReqCtx {
}
pub type ReqCtxArc = std::sync::Arc<ReqCtx>;
pub fn req_uri_to_url(uri: &Uri) -> Result<Url, Error> {
if uri.scheme().is_none() {
format!("dummy:{uri}")
.parse()
.map_err(|_| Error::with_msg_no_trace(format!("can not use uri {uri}")))
} else {
uri.to_string()
.parse()
.map_err(|_| Error::with_msg_no_trace(format!("can not use uri {uri}")))
}
}