From 2761639b9a74f780b6d66cbb390e8726f44aded1 Mon Sep 17 00:00:00 2001 From: Ziheng Liu Date: Sun, 4 Feb 2024 20:47:33 +0800 Subject: [PATCH] fixed 9c20bd8 from https://gitee.com/zh_liu/commonlibrary_rust_ylong_http/pulls/76 add a no proxy domain contain rule Signed-off-by: Ziheng Liu --- ylong_http_client/src/util/proxy.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ylong_http_client/src/util/proxy.rs b/ylong_http_client/src/util/proxy.rs index 15ba9c6..d38d80d 100644 --- a/ylong_http_client/src/util/proxy.rs +++ b/ylong_http_client/src/util/proxy.rs @@ -243,16 +243,25 @@ impl NoProxy { fn contains_domain(&self, domain: &str) -> bool { for block_domain in self.domains.iter() { + let mut block_domain = block_domain.clone(); + // Changes *.example.com to .example.com + if (block_domain.starts_with('*')) && (block_domain.len() > 1) { + block_domain = block_domain.trim_matches('*').to_string(); + } + if block_domain == "*" || block_domain.ends_with(domain) || block_domain == domain || block_domain.trim_matches('.') == domain { return true; - } else if domain.ends_with(block_domain) { + } else if domain.ends_with(&block_domain) { // .example.com and www. if block_domain.starts_with('.') - || domain.as_bytes().get(domain.len() - block_domain.len() - 1) == Some(&b'.') + || domain + .as_bytes() + .get(domain.len() - block_domain.len() - 1) + == Some(&b'.') { return true; } -- Gitee