diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-06 06:25:10 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-06 06:25:30 +0900 |
| commit | 791ef1cd465597ff43dab4216c4b00e9e4160da8 (patch) | |
| tree | ec6c3bc45f81576146325350faa6dcea638987b4 /crates/shirabe/src/util/http/curl_downloader.rs | |
| parent | a86bbd67954f7bbc38bb09138edb335d82666526 (diff) | |
| download | php-shirabe-791ef1cd465597ff43dab4216c4b00e9e4160da8.tar.gz php-shirabe-791ef1cd465597ff43dab4216c4b00e9e4160da8.tar.zst php-shirabe-791ef1cd465597ff43dab4216c4b00e9e4160da8.zip | |
refactor(php-shim): split in_array into strict and loose variants
Diffstat (limited to 'crates/shirabe/src/util/http/curl_downloader.rs')
| -rw-r--r-- | crates/shirabe/src/util/http/curl_downloader.rs | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs index 2d2259b9..64ff42a6 100644 --- a/crates/shirabe/src/util/http/curl_downloader.rs +++ b/crates/shirabe/src/util/http/curl_downloader.rs @@ -33,7 +33,8 @@ use crate::util::{AuthHelper, PromptAuthResult, StoreAuth}; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::{ - PhpMixed, in_array, parse_url, php_regex, preg_quote, rename, strpos, substr, unlink_silent, + PhpMixed, in_array_loose, in_array_strict, parse_url, php_regex, preg_quote, rename, strpos, + substr, unlink_silent, }; use std::sync::atomic::{AtomicBool, Ordering}; @@ -412,15 +413,12 @@ impl CurlDownloader { .and_then(|v| v.as_int()) .unwrap_or(0); if Self::method_is_get(options) - && in_array( - PhpMixed::Int(status_code), - &PhpMixed::List( - [423, 425, 500, 502, 503, 504, 507, 510] - .iter() - .map(|c| PhpMixed::Int(*c)) - .collect(), - ), - true, + && in_array_strict( + status_code, + &[423, 425, 500, 502, 503, 504, 507, 510] + .iter() + .map(|c| PhpMixed::Int(*c)) + .collect::<Vec<_>>(), ) && retries < self.max_retries { @@ -717,10 +715,9 @@ impl CurlDownloader { .and_then(|b| b.as_int()) .unwrap_or(0); - if in_array( - PhpMixed::Int(response.inner.get_status_code()), - &PhpMixed::List(vec![PhpMixed::Int(401), PhpMixed::Int(403)]), - false, + if in_array_loose( + response.inner.get_status_code(), + &[PhpMixed::Int(401), PhpMixed::Int(403)], ) && retry_auth_failure { let status_message = response.inner.get_status_message(); @@ -767,11 +764,7 @@ impl CurlDownloader { _ => Vec::new(), }; if response.inner.get_status_code() == 404 - && in_array( - PhpMixed::String(origin.to_string()), - &PhpMixed::List(gitlab_domains_list), - true, - ) + && in_array_strict(origin.to_string(), &gitlab_domains_list) && strpos(url, "archive.zip").is_some() { needs_auth_retry = Some("GitLab requires authentication and it was not provided"); @@ -827,19 +820,16 @@ impl CurlDownloader { } let mut details = String::new(); - if in_array( - PhpMixed::String( - response - .inner - .get_header("content-type") - .unwrap_or_default() - .to_lowercase(), - ), - &PhpMixed::List(vec![ + if in_array_strict( + response + .inner + .get_header("content-type") + .unwrap_or_default() + .to_lowercase(), + &[ PhpMixed::String("application/json".to_string()), PhpMixed::String("application/json; charset=utf-8".to_string()), - ]), - true, + ], ) { let body = response.inner.get_body().unwrap_or(""); details = format!( |
