aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/no_proxy_pattern.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 10:00:50 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 10:00:50 +0900
commit112df62a01e482f33b68e1dac190f70085fcec64 (patch)
tree19d126032309193cfd5f5d0fb63b6562ef17e5c9 /crates/shirabe/src/util/no_proxy_pattern.rs
parent3fb08fab7ca69a028a9a89544b246ca70534cbce (diff)
downloadphp-shirabe-112df62a01e482f33b68e1dac190f70085fcec64.tar.gz
php-shirabe-112df62a01e482f33b68e1dac190f70085fcec64.tar.zst
php-shirabe-112df62a01e482f33b68e1dac190f70085fcec64.zip
refactor(php-shim): give parse_url a typed UrlComponents result
parse_url now returns Option<UrlComponents> instead of a PhpMixed array, and the component-selecting overload with the PHP_URL_* constants is gone: callers read the field they want. Two call sites change behaviour as a result, both towards PHP: * CurlDownloader::handle_redirect tested scheme and host with is_null(), so an unparsable Location header (PhpMixed::Bool(false)) counted as an absolute URL. PHP's truthiness test sends it to the relative-path branch. * Url::get_origin appended a literal port 0, which PHP treats as falsy and leaves off. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/no_proxy_pattern.rs')
-rw-r--r--crates/shirabe/src/util/no_proxy_pattern.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/crates/shirabe/src/util/no_proxy_pattern.rs b/crates/shirabe/src/util/no_proxy_pattern.rs
index 6d19637a..85e1f472 100644
--- a/crates/shirabe/src/util/no_proxy_pattern.rs
+++ b/crates/shirabe/src/util/no_proxy_pattern.rs
@@ -3,9 +3,8 @@
use indexmap::IndexMap;
use shirabe_pcre::Preg;
use shirabe_php_shim::{
- PHP_URL_HOST, PHP_URL_PORT, PHP_URL_SCHEME, PhpMixed, RuntimeException, array_key_exists,
- empty, explode, filter_var_int_with_range, filter_var_ip, inet_pton, ltrim, parse_url,
- php_regex, stripos, strlen, strpbrk, strpos, substr, substr_count,
+ RuntimeException, array_key_exists, explode, filter_var_int_with_range, filter_var_ip,
+ inet_pton, ltrim, parse_url, php_regex, stripos, strlen, strpbrk, strpos, substr, substr_count,
};
/// Tests URLs against NO_PROXY patterns
@@ -70,23 +69,26 @@ impl NoProxyPattern {
/// Returns false is the url cannot be parsed, otherwise a data object
fn get_url_data(&self, url: &str) -> anyhow::Result<Option<UrlData>> {
- let host = parse_url(url, PHP_URL_HOST);
- if empty(&host) {
+ let parsed = parse_url(url);
+ let Some(host_str) = parsed
+ .as_ref()
+ .and_then(|parsed| parsed.host.clone())
+ .filter(|host| !host.is_empty() && host != "0")
+ else {
return Ok(None);
- }
- let host_str = host.as_string().unwrap_or("").to_string();
+ };
- let mut port_mixed = parse_url(url, PHP_URL_PORT);
+ let mut port = parsed.as_ref().and_then(|parsed| parsed.port);
- if empty(&port_mixed) {
- match parse_url(url, PHP_URL_SCHEME).as_string() {
- Some("http") => port_mixed = PhpMixed::Int(80),
- Some("https") => port_mixed = PhpMixed::Int(443),
+ if port.is_none_or(|port| port == 0) {
+ match parsed.as_ref().and_then(|parsed| parsed.scheme.as_deref()) {
+ Some("http") => port = Some(80),
+ Some("https") => port = Some(443),
_ => {}
}
}
- let port_int = port_mixed.as_int().unwrap_or(0);
+ let port_int = port.unwrap_or(0);
let host_name = format!(
"{}{}",
host_str,