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.rs60
-rw-r--r--crates/shirabe/src/util/http/proxy_manager.rs16
-rw-r--r--crates/shirabe/src/util/http/response.rs2
3 files changed, 38 insertions, 40 deletions
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index d335b8b..c475ad3 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -51,7 +51,7 @@ pub struct CurlDownloader {
/// @var IOInterface
io: Box<dyn IOInterface>,
/// @var Config
- config: Config,
+ config: std::rc::Rc<std::cell::RefCell<Config>>,
/// @var AuthHelper
auth_helper: AuthHelper,
/// @var float
@@ -124,7 +124,7 @@ impl CurlDownloader {
/// @param mixed[] $options
pub fn new(
io: Box<dyn IOInterface>,
- config: Config,
+ config: std::rc::Rc<std::cell::RefCell<Config>>,
_options: IndexMap<String, PhpMixed>,
_disable_tls: bool,
) -> Self {
@@ -336,10 +336,11 @@ impl CurlDownloader {
let original_options = options.clone();
// check URL can be accessed (i.e. is not insecure), but allow insecure Packagist calls to $hashed providers as file integrity is verified with sha256
- if !Preg::is_match(r"{^http://(repo\.)?packagist\.org/p/}", url)
+ if !Preg::is_match(r"{^http://(repo\.)?packagist\.org/p/}", url).unwrap_or(false)
|| (strpos(url, "$").is_none() && strpos(url, "%24").is_none())
{
self.config
+ .borrow_mut()
.prohibit_url_by_config(url, Some(&*self.io), &options)?;
}
@@ -681,13 +682,13 @@ impl CurlDownloader {
if attributes.get("redirects").and_then(|v| v.as_int()) == Some(0)
&& attributes.get("retries").and_then(|v| v.as_int()) == Some(0)
{
- self.io.write_error(
- PhpMixed::String(format!(
+ self.io.write_error3(
+ &format!(
"Downloading {}{}{}",
Url::sanitize(url.to_string()),
using_proxy,
if_modified
- )),
+ ),
true,
crate::io::io_interface::DEBUG,
);
@@ -830,11 +831,8 @@ impl CurlDownloader {
&& !TIMEOUT_WARNING.load(Ordering::Relaxed)
{
TIMEOUT_WARNING.store(true, Ordering::Relaxed);
- self.io.write_error(
- PhpMixed::String(
- "<warning>A connection timeout was encountered. If you intend to run Composer without connecting to the internet, run the command again prefixed with COMPOSER_DISABLE_NETWORK=1 to make Composer run in offline mode.</warning>"
- .to_string(),
- ),
+ self.io.write_error3(
+ "<warning>A connection timeout was encountered. If you intend to run Composer without connecting to the internet, run the command again prefixed with COMPOSER_DISABLE_NETWORK=1 to make Composer run in offline mode.</warning>",
true,
crate::io::io_interface::NORMAL,
);
@@ -904,8 +902,8 @@ impl CurlDownloader {
// CURLE_COULDNT_CONNECT, retry forcing IPv4 if no IP stack was selected
attributes.insert("ipResolve".to_string(), PhpMixed::Int(4));
}
- self.io.write_error(
- PhpMixed::String(format!(
+ self.io.write_error3(
+ &format!(
"Retrying ({}) {} due to curl error {}",
job.get("attributes")
.and_then(|v| v.as_array())
@@ -920,7 +918,7 @@ impl CurlDownloader {
.to_string()
),
errno
- )),
+ ),
true,
crate::io::io_interface::DEBUG,
);
@@ -936,8 +934,8 @@ impl CurlDownloader {
if errno == 55
/* CURLE_SEND_ERROR */
{
- self.io.write_error(
- PhpMixed::String(format!(
+ self.io.write_error3(
+ &format!(
"Retrying ({}) {} due to curl error {}",
job.get("attributes")
.and_then(|v| v.as_array())
@@ -952,7 +950,7 @@ impl CurlDownloader {
.to_string()
),
errno
- )),
+ ),
true,
crate::io::io_interface::DEBUG,
);
@@ -1073,8 +1071,8 @@ impl CurlDownloader {
.map(|(k, v)| (k.clone(), (**v).clone()))
.collect(),
));
- self.io.write_error(
- PhpMixed::String(format!(
+ self.io.write_error3(
+ &format!(
"[{}] {}",
status_code.unwrap_or(0),
Url::sanitize(
@@ -1083,7 +1081,7 @@ impl CurlDownloader {
.unwrap_or("")
.to_string()
)
- )),
+ ),
true,
crate::io::io_interface::DEBUG,
);
@@ -1149,8 +1147,8 @@ impl CurlDownloader {
.map(|(k, v)| (k.clone(), (**v).clone()))
.collect(),
));
- self.io.write_error(
- PhpMixed::String(format!(
+ self.io.write_error3(
+ &format!(
"[{}] {}",
status_code.unwrap_or(0),
Url::sanitize(
@@ -1159,7 +1157,7 @@ impl CurlDownloader {
.unwrap_or("")
.to_string()
)
- )),
+ ),
true,
crate::io::io_interface::DEBUG,
);
@@ -1292,8 +1290,8 @@ impl CurlDownloader {
.unwrap_or(0)
< self.max_retries
{
- self.io.write_error(
- PhpMixed::String(format!(
+ self.io.write_error3(
+ &format!(
"Retrying ({}) {} due to status code {}",
job.get("attributes")
.and_then(|v| v.as_array())
@@ -1308,7 +1306,7 @@ impl CurlDownloader {
.to_string()
),
sc
- )),
+ ),
true,
crate::io::io_interface::DEBUG,
);
@@ -1598,8 +1596,8 @@ impl CurlDownloader {
}
if !target_url.is_empty() {
- self.io.write_error(
- PhpMixed::String(sprintf(
+ self.io.write_error3(
+ &sprintf(
"Following redirect (%u) %s",
&[
PhpMixed::Int(
@@ -1612,7 +1610,7 @@ impl CurlDownloader {
),
PhpMixed::String(Url::sanitize(target_url.clone())),
],
- )),
+ ),
true,
crate::io::io_interface::DEBUG,
);
@@ -1697,7 +1695,7 @@ impl CurlDownloader {
}
// check for gitlab 404 when downloading archives
- let gitlab_domains = self.config.get("gitlab-domains");
+ let gitlab_domains = self.config.borrow_mut().get("gitlab-domains");
let gitlab_domains_list: Vec<Box<PhpMixed>> = match gitlab_domains {
PhpMixed::List(l) => l,
_ => Vec::new(),
@@ -1788,7 +1786,7 @@ impl CurlDownloader {
PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(),
_ => IndexMap::new(),
};
- let origin = Url::get_origin(&self.config, url);
+ let origin = Url::get_origin(&*self.config.borrow(), url);
let copy_to = job
.get("filename")
diff --git a/crates/shirabe/src/util/http/proxy_manager.rs b/crates/shirabe/src/util/http/proxy_manager.rs
index 5ed8269..2576dcb 100644
--- a/crates/shirabe/src/util/http/proxy_manager.rs
+++ b/crates/shirabe/src/util/http/proxy_manager.rs
@@ -50,10 +50,10 @@ impl ProxyManager {
request_url: &str,
) -> Result<RequestProxy, TransportException> {
if let Some(ref error) = self.error {
- return Err(TransportException::new(format!(
- "Unable to use a proxy: {}",
- error
- )));
+ return Err(TransportException::new(
+ format!("Unable to use a proxy: {}", error),
+ 0,
+ ));
}
let scheme = request_url.split("://").next().unwrap_or("").to_string();
@@ -85,19 +85,19 @@ impl ProxyManager {
// PHP_SAPI is always 'cli' for this application
let (env, name) = Self::get_proxy_env("http_proxy");
if let Some(env) = env {
- self.http_proxy = Some(ProxyItem::new(env, name));
+ self.http_proxy = Some(ProxyItem::new(env, name)?);
}
if self.http_proxy.is_none() {
let (env, name) = Self::get_proxy_env("cgi_http_proxy");
if let Some(env) = env {
- self.http_proxy = Some(ProxyItem::new(env, name));
+ self.http_proxy = Some(ProxyItem::new(env, name)?);
}
}
let (env, name) = Self::get_proxy_env("https_proxy");
if let Some(env) = env {
- self.https_proxy = Some(ProxyItem::new(env, name));
+ self.https_proxy = Some(ProxyItem::new(env, name)?);
}
let (env, _name) = Self::get_proxy_env("no_proxy");
@@ -122,7 +122,7 @@ impl ProxyManager {
fn no_proxy(&self, request_url: &str) -> bool {
match &self.no_proxy_handler {
None => false,
- Some(handler) => handler.test(request_url),
+ Some(handler) => handler.test(request_url).unwrap_or(false),
}
}
}
diff --git a/crates/shirabe/src/util/http/response.rs b/crates/shirabe/src/util/http/response.rs
index cf238c7..62458d6 100644
--- a/crates/shirabe/src/util/http/response.rs
+++ b/crates/shirabe/src/util/http/response.rs
@@ -41,7 +41,7 @@ impl Response {
pub fn get_status_message(&self) -> Option<String> {
let mut value = None;
for header in &self.headers {
- if Preg::is_match(r"(?i)^HTTP/\S+ \d+", header) {
+ if Preg::is_match(r"(?i)^HTTP/\S+ \d+", header).unwrap_or(false) {
// In case of redirects, headers contain the headers of all responses
// so we can not return directly and need to keep iterating
value = Some(header.clone());