aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/http
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/util/http')
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs58
-rw-r--r--crates/shirabe/src/util/http/proxy_item.rs34
-rw-r--r--crates/shirabe/src/util/http/proxy_manager.rs6
-rw-r--r--crates/shirabe/src/util/http/request_proxy.rs9
4 files changed, 49 insertions, 58 deletions
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index 604dae77..6409c9d5 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -60,7 +60,7 @@ static TIMEOUT_WARNING: AtomicBool = AtomicBool::new(false);
enum Decision {
Retry { url: String, delay_ms: Option<u64> },
Done(Response),
- Failed(TransportException),
+ Failed(anyhow::Error),
}
impl CurlDownloader {
@@ -108,7 +108,7 @@ impl CurlDownloader {
url: &str,
mut options: IndexMap<String, PhpMixed>,
copy_to: Option<&str>,
- ) -> anyhow::Result<Result<Response, TransportException>> {
+ ) -> anyhow::Result<Result<Response, anyhow::Error>> {
let mut attributes: IndexMap<String, PhpMixed> = {
let mut m = IndexMap::new();
m.insert("retryAuthFailure".to_string(), PhpMixed::Bool(true));
@@ -178,7 +178,7 @@ impl CurlDownloader {
.as_ref()
.map(|pm| pm.get_proxy_for_request(url))
.transpose()
- .map_err(|e| anyhow::anyhow!(e.message))?
+ .map_err(|e| anyhow::anyhow!(e.get_message().to_string()))?
.and_then(|p| p.get_status(Some(" using proxy (%s)")).ok())
.unwrap_or_default();
// `attributes.redirects == 0 && attributes.retries == 0` in PHP is always true here since
@@ -206,7 +206,7 @@ impl CurlDownloader {
)?;
let send_options =
crate::util::StreamContextFactory::init_options(&current_url, send_options, true)
- .map_err(|e| anyhow::anyhow!(e.message))?;
+ .map_err(|e| anyhow::anyhow!(e.get_message().to_string()))?;
let send_result = self
.send_once(&current_url, &send_options, copy_to, &attributes)
@@ -304,26 +304,24 @@ impl CurlDownloader {
if let Some(filename) = filename {
unlink_silent(format!("{}~", filename));
}
- // PHP throws a MaxFileSizeExceededException (a TransportException subclass) with
- // the raw "Maximum allowed download size reached..." message verbatim rather than
- // wrapping it in the generic curl-error text.
+ // The message carries the raw "Maximum allowed download size reached..." text
+ // rather than the generic curl-error wrapper used below.
if transport_err.is_max_file_size {
return Ok(Decision::Failed(
- MaxFileSizeExceededException(TransportException::new(
- transport_err.message,
- 0,
- ))
- .0,
+ MaxFileSizeExceededException::new(transport_err.message).into(),
));
}
- return Ok(Decision::Failed(TransportException::new(
- format!(
- "curl error while downloading {}: {}",
- Url::sanitize(url.to_string()),
- transport_err.message
- ),
- 0,
- )));
+ return Ok(Decision::Failed(
+ TransportException::new(
+ format!(
+ "curl error while downloading {}: {}",
+ Url::sanitize(url.to_string()),
+ transport_err.message
+ ),
+ 0,
+ )
+ .into(),
+ ));
}
};
@@ -373,7 +371,7 @@ impl CurlDownloader {
});
}
Ok(_) => {}
- Err(e) => return Ok(Decision::Failed(e)),
+ Err(e) => return Ok(Decision::Failed((*e).into())),
}
// Handle 3xx redirects, 304 Not Modified excluded.
@@ -401,7 +399,7 @@ impl CurlDownloader {
if let Some(filename) = filename {
unlink_silent(format!("{}~", filename));
}
- return Ok(Decision::Failed(e));
+ return Ok(Decision::Failed((*e).into()));
}
}
}
@@ -443,7 +441,7 @@ impl CurlDownloader {
e.set_headers(curl_response.inner.get_headers().clone());
e.set_status_code(Some(curl_response.inner.get_status_code()));
e.set_response(curl_response.inner.get_body().map(|s| s.to_string()));
- return Ok(Decision::Failed(e));
+ return Ok(Decision::Failed((*e).into()));
}
// storeAuth on success.
@@ -625,7 +623,7 @@ impl CurlDownloader {
url: &str,
attributes: &IndexMap<String, PhpMixed>,
response: &CurlResponse,
- ) -> anyhow::Result<Result<String, TransportException>> {
+ ) -> anyhow::Result<Result<String, Box<TransportException>>> {
let mut target_url = String::new();
if let Some(location_header) = response.inner.get_header("location")
&& !location_header.is_empty()
@@ -682,14 +680,14 @@ impl CurlDownloader {
return Ok(Ok(target_url));
}
- Ok(Err(TransportException::new(
+ Ok(Err(Box::new(TransportException::new(
format!(
"The \"{}\" file could not be downloaded, got redirect without Location ({})",
url,
response.inner.get_status_message().unwrap_or_default()
),
0,
- )))
+ ))))
}
fn is_authenticated_retry_needed(
@@ -699,7 +697,7 @@ impl CurlDownloader {
filename: Option<&str>,
attributes: &IndexMap<String, PhpMixed>,
response: &CurlResponse,
- ) -> anyhow::Result<Result<PromptAuthResult, TransportException>> {
+ ) -> anyhow::Result<Result<PromptAuthResult, Box<TransportException>>> {
let retry_auth_failure = attributes
.get("retryAuthFailure")
.and_then(|b| b.as_bool())
@@ -808,7 +806,7 @@ impl CurlDownloader {
filename: Option<&str>,
response: &CurlResponse,
error_message: &str,
- ) -> TransportException {
+ ) -> Box<TransportException> {
if let Some(filename) = filename {
unlink_silent(format!("{}~", filename));
}
@@ -836,13 +834,13 @@ impl CurlDownloader {
);
}
- TransportException::new(
+ Box::new(TransportException::new(
format!(
"The \"{}\" file could not be downloaded ({}){}",
url, error_message, details
),
response.inner.get_status_code(),
- )
+ ))
}
fn method_is_get(options: &IndexMap<String, PhpMixed>) -> bool {
diff --git a/crates/shirabe/src/util/http/proxy_item.rs b/crates/shirabe/src/util/http/proxy_item.rs
index 1a0b3ee8..73948f88 100644
--- a/crates/shirabe/src/util/http/proxy_item.rs
+++ b/crates/shirabe/src/util/http/proxy_item.rs
@@ -20,28 +20,22 @@ impl ProxyItem {
let syntax_error = format!("unsupported `{}` syntax", env_name);
if strpbrk(&proxy_url, "\r\n\t").is_some() {
- return Err(RuntimeException {
- message: syntax_error,
- code: 0,
- });
+ return Err(RuntimeException::new(syntax_error));
}
let proxy_parsed = parse_url_all(&proxy_url);
let proxy = match proxy_parsed.as_array() {
None => {
- return Err(RuntimeException {
- message: syntax_error,
- code: 0,
- });
+ return Err(RuntimeException::new(syntax_error));
}
Some(a) => a.clone(),
};
if !proxy.contains_key("host") {
- return Err(RuntimeException {
- message: format!("unable to find proxy host in {}", env_name),
- code: 0,
- });
+ return Err(RuntimeException::new(format!(
+ "unable to find proxy host in {}",
+ env_name
+ )));
}
let scheme = if proxy.contains_key("scheme") {
@@ -100,16 +94,16 @@ impl ProxyItem {
// but is considered valid depending on the PHP or Curl version.
let port = match port {
None => {
- return Err(RuntimeException {
- message: format!("unable to find proxy port in {}", env_name),
- code: 0,
- });
+ return Err(RuntimeException::new(format!(
+ "unable to find proxy port in {}",
+ env_name
+ )));
}
Some(0) => {
- return Err(RuntimeException {
- message: format!("port 0 is reserved in {}", env_name),
- code: 0,
- });
+ return Err(RuntimeException::new(format!(
+ "port 0 is reserved in {}",
+ env_name
+ )));
}
Some(p) => p,
};
diff --git a/crates/shirabe/src/util/http/proxy_manager.rs b/crates/shirabe/src/util/http/proxy_manager.rs
index 82e8ebc5..13f0b521 100644
--- a/crates/shirabe/src/util/http/proxy_manager.rs
+++ b/crates/shirabe/src/util/http/proxy_manager.rs
@@ -71,12 +71,12 @@ impl ProxyManager {
pub fn get_proxy_for_request(
&self,
request_url: &str,
- ) -> Result<RequestProxy, TransportException> {
+ ) -> Result<RequestProxy, Box<TransportException>> {
if let Some(ref error) = self.error {
- return Err(TransportException::new(
+ return Err(Box::new(TransportException::new(
format!("Unable to use a proxy: {}", error),
0,
- ));
+ )));
}
let scheme = request_url.split("://").next().unwrap_or("").to_string();
diff --git a/crates/shirabe/src/util/http/request_proxy.rs b/crates/shirabe/src/util/http/request_proxy.rs
index 1262622f..78a64078 100644
--- a/crates/shirabe/src/util/http/request_proxy.rs
+++ b/crates/shirabe/src/util/http/request_proxy.rs
@@ -48,7 +48,7 @@ impl RequestProxy {
pub fn get_curl_options(
&self,
ssl_options: &IndexMap<String, PhpMixed>,
- ) -> Result<IndexMap<i64, PhpMixed>, TransportException> {
+ ) -> Result<IndexMap<i64, PhpMixed>, Box<TransportException>> {
// PHP guards an HTTPS proxy behind `is_secure() && !supports_secure_proxy()` because
// libcurl < 7.52.0 cannot speak TLS to a proxy. Shirabe always can (see
// supports_secure_proxy), so the guard is dropped.
@@ -90,10 +90,9 @@ impl RequestProxy {
return Ok(format.replace("%s", self.status.as_deref().unwrap()));
}
- Err(InvalidArgumentException {
- message: "String format specifier is missing".to_string(),
- code: 0,
- })
+ Err(InvalidArgumentException::new(
+ "String format specifier is missing".to_string(),
+ ))
}
pub fn is_excluded_by_no_proxy(&self) -> bool {