From 259c78a5d15a745a1d09b04c121c2ee69f8bbeba Mon Sep 17 00:00:00 2001 From: jhengazuki Date: Mon, 25 Aug 2025 13:38:15 +0800 Subject: [PATCH] Update proxy hosts --- README.md | 19 +++++++++++++++---- .../java/com/github/catvod/bean/Proxy.java | 9 ++++----- .../github/catvod/net/OkAuthenticator.java | 16 +++++++++------- .../github/catvod/net/OkProxySelector.java | 2 +- other/sample/config.json | 17 ++++++++++++++--- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 15c97d872..b03da9574 100644 --- a/README.md +++ b/README.md @@ -155,19 +155,30 @@ http://127.0.0.1:9978/cache?do=del&key=xxx scheme://username:password@host:port ``` -配置新增 proxy 可指定走哪條代理 +配置新增 proxy 可指定代理 ```json { "spider": "", "proxy": [ { - "name": "Global", - "host": ".*.", + "name": "全局", + "hosts": [ + ".*." + ], "urls": [ - "http://127.0.0.1:7890", "socks5://127.0.0.1:7891" ] + }, + { + "name": "自訂", + "hosts": [ + "googlevideo.com", + "raw.githubusercontent.com" + ], + "urls": [ + "http://127.0.0.1:7890" + ] } ] } diff --git a/catvod/src/main/java/com/github/catvod/bean/Proxy.java b/catvod/src/main/java/com/github/catvod/bean/Proxy.java index e2d47bedb..beb66dc33 100644 --- a/catvod/src/main/java/com/github/catvod/bean/Proxy.java +++ b/catvod/src/main/java/com/github/catvod/bean/Proxy.java @@ -1,7 +1,6 @@ package com.github.catvod.bean; import android.net.Uri; -import android.text.TextUtils; import com.google.gson.Gson; import com.google.gson.JsonElement; @@ -17,8 +16,8 @@ import java.util.Objects; public class Proxy { - @SerializedName("host") - private String host; + @SerializedName("hosts") + private List hosts; @SerializedName("urls") private List urls; @@ -34,8 +33,8 @@ public class Proxy { } } - public String getHost() { - return TextUtils.isEmpty(host) ? "" : host; + public List getHosts() { + return hosts == null ? Collections.emptyList() : hosts; } public List getUrls() { diff --git a/catvod/src/main/java/com/github/catvod/net/OkAuthenticator.java b/catvod/src/main/java/com/github/catvod/net/OkAuthenticator.java index ce55b807e..d21447ba6 100644 --- a/catvod/src/main/java/com/github/catvod/net/OkAuthenticator.java +++ b/catvod/src/main/java/com/github/catvod/net/OkAuthenticator.java @@ -39,15 +39,17 @@ public class OkAuthenticator implements Authenticator { public Request authenticate(@Nullable Route route, @NonNull Response response) { if (route == null || response.request().header(HttpHeaders.PROXY_AUTHORIZATION) != null) return null; if (!(route.proxy().address() instanceof InetSocketAddress proxyAddress)) return null; + String requestHost = response.request().url().host(); String proxyHost = proxyAddress.getHostName(); - String host = response.request().url().host(); for (Proxy item : proxy) { - if (Util.containOrMatch(host, item.getHost())) { - for (String url : item.getUrls()) { - if (url.contains(proxyHost)) { - String userInfo = Uri.parse(url).getUserInfo(); - if (userInfo != null) { - return response.request().newBuilder().header(HttpHeaders.PROXY_AUTHORIZATION, Util.basic(userInfo)).build(); + for (String host : item.getHosts()) { + if (Util.containOrMatch(requestHost, host)) { + for (String url : item.getUrls()) { + if (url.contains(proxyHost)) { + String userInfo = Uri.parse(url).getUserInfo(); + if (userInfo != null) { + return response.request().newBuilder().header(HttpHeaders.PROXY_AUTHORIZATION, Util.basic(userInfo)).build(); + } } } } diff --git a/catvod/src/main/java/com/github/catvod/net/OkProxySelector.java b/catvod/src/main/java/com/github/catvod/net/OkProxySelector.java index d0480ea59..b89d6fa14 100644 --- a/catvod/src/main/java/com/github/catvod/net/OkProxySelector.java +++ b/catvod/src/main/java/com/github/catvod/net/OkProxySelector.java @@ -29,7 +29,7 @@ public class OkProxySelector extends ProxySelector { @Override public List select(URI uri) { if (proxy.isEmpty() || uri.getHost() == null || "127.0.0.1".equals(uri.getHost())) return Proxy.NO_PROXY; - for (Proxy item : proxy) if (Util.containOrMatch(uri.getHost(), item.getHost())) return item.select(); + for (Proxy item : proxy) for (String host : item.getHosts()) if (Util.containOrMatch(uri.getHost(), host)) return item.select(); return Proxy.NO_PROXY; } diff --git a/other/sample/config.json b/other/sample/config.json index 2397fda36..7c4f4acd6 100644 --- a/other/sample/config.json +++ b/other/sample/config.json @@ -36,12 +36,23 @@ ], "proxy": [ { - "name": "Global", - "host": ".*.", + "name": "全局", + "hosts": [ + ".*." + ], "urls": [ - "http://127.0.0.1:7890", "socks5://127.0.0.1:7891" ] + }, + { + "name": "自訂", + "hosts": [ + "googlevideo.com", + "raw.githubusercontent.com" + ], + "urls": [ + "http://127.0.0.1:7890" + ] } ], "rules": [