refactor: HttpUtils改为单例INSTANCE

This commit is contained in:
mediabot-pt
2026-07-01 23:14:17 +08:00
parent ad9cfad5d9
commit 0288af1866
2 changed files with 3 additions and 1 deletions

View File

@@ -71,7 +71,7 @@ public class GroovyScriptEngine {
binding.setVariable("jsoup", new JsoupHelper()); binding.setVariable("jsoup", new JsoupHelper());
binding.setVariable("json", objectMapper); binding.setVariable("json", objectMapper);
binding.setVariable("utils", new ScriptUtils()); binding.setVariable("utils", new ScriptUtils());
binding.setVariable("http", new HttpUtils()); binding.setVariable("http", HttpUtils.INSTANCE);
GroovyShell shell = new GroovyShell(classLoader, binding); GroovyShell shell = new GroovyShell(classLoader, binding);
String fullScript = SCRIPT_PREFIX + groovyScript + "\n// PAR 调用入口\nreturn parse(content, url)"; String fullScript = SCRIPT_PREFIX + groovyScript + "\n// PAR 调用入口\nreturn parse(content, url)";

View File

@@ -13,6 +13,8 @@ import java.time.Duration;
*/ */
public class HttpUtils { public class HttpUtils {
public static final HttpUtils INSTANCE = new HttpUtils();
private static final HttpClient client = HttpClient.newBuilder() private static final HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10)) .connectTimeout(Duration.ofSeconds(10))
.followRedirects(HttpClient.Redirect.NORMAL) .followRedirects(HttpClient.Redirect.NORMAL)