diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index d1526d9dd..779bc19be 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -1381,7 +1381,10 @@ impl Client { } } - let uri = expect_uri(&url); + let uri = match expect_uri(&url) { + Ok(uri) => uri, + _ => return Pending::new_err(error::url_invalid_uri(url)), + }; let (reusable, body) = match body { Some(body) => { @@ -1794,7 +1797,7 @@ impl Future for PendingRequest { std::mem::replace(self.as_mut().headers(), HeaderMap::new()); remove_sensitive_headers(&mut headers, &self.url, &self.urls); - let uri = expect_uri(&self.url); + let uri = expect_uri(&self.url)?; let body = match self.body { Some(Some(ref body)) => Body::reusable(body.clone()), _ => Body::empty(), diff --git a/src/error.rs b/src/error.rs index fb73de97f..830602f79 100644 --- a/src/error.rs +++ b/src/error.rs @@ -257,6 +257,10 @@ pub(crate) fn url_bad_scheme(url: Url) -> Error { Error::new(Kind::Builder, Some("URL scheme is not allowed")).with_url(url) } +pub(crate) fn url_invalid_uri(url: Url) -> Error { + Error::new(Kind::Builder, Some("Parsed Url is not a valid Uri")).with_url(url) +} + if_wasm! { pub(crate) fn wasm(js_val: wasm_bindgen::JsValue) -> BoxError { format!("{:?}", js_val).into() diff --git a/src/into_url.rs b/src/into_url.rs index ef0db9495..caf80e7e2 100644 --- a/src/into_url.rs +++ b/src/into_url.rs @@ -64,10 +64,10 @@ impl<'a> IntoUrlSealed for String { } if_hyper! { - pub(crate) fn expect_uri(url: &Url) -> http::Uri { + pub(crate) fn expect_uri(url: &Url) -> crate::Result { url.as_str() .parse() - .expect("a parsed Url should always be a valid Uri") + .map_err(|_| crate::error::url_invalid_uri(url.clone())) } pub(crate) fn try_uri(url: &Url) -> Option {