From 247d79a4fb90d87bad05cc8961c22f2218a35781 Mon Sep 17 00:00:00 2001 From: Looly Date: Sun, 15 Jan 2023 11:21:21 +0800 Subject: [PATCH] =?UTF-8?q?HttpGlobalConfig.allowPatch()=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E6=97=B6=E5=BF=BD=E7=95=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../src/main/java/cn/hutool/http/HttpConnection.java | 7 ++++++- .../src/main/java/cn/hutool/http/HttpGlobalConfig.java | 3 +-- hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java | 5 +++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c83be53ea..003c25b7e 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### 🐣新特性 * 【core 】 XmlUtil.readObjectFromXml增加注入漏洞的警告注释,并标识为废弃(issue#2857@Github) +* 【http 】 HttpGlobalConfig.allowPatch()调用时忽略错误(issue#2832@Github) ### 🐞Bug修复 * 【core 】 修复HexUtil.isHexNumber()对"-"的判断问题(issue#2857@Github) diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java b/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java index a2c23c419..024ca8530 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java @@ -120,7 +120,12 @@ public class HttpConnection { // 增加PATCH方法支持 if (Method.PATCH.equals(method)) { - HttpGlobalConfig.allowPatch(); + try { + HttpGlobalConfig.allowPatch(); + } catch (Exception ignore){ + // ignore + // https://github.com/dromara/hutool/issues/2832 + } } } diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpGlobalConfig.java b/hutool-http/src/main/java/cn/hutool/http/HttpGlobalConfig.java index a215caac8..75e7b71a1 100755 --- a/hutool-http/src/main/java/cn/hutool/http/HttpGlobalConfig.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpGlobalConfig.java @@ -7,7 +7,6 @@ import cn.hutool.http.cookie.GlobalCookieManager; import java.io.Serializable; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.net.CookieManager; import java.net.HttpURLConnection; @@ -198,7 +197,7 @@ public class HttpGlobalConfig implements Serializable { } // 去除final修饰 - ReflectUtil.setFieldValue(methodsField, "modifiers", methodsField.getModifiers() & ~Modifier.FINAL); + ReflectUtil.removeFinalModify(methodsField); final String[] methods = { "GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE", "PATCH" }; diff --git a/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java b/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java index fe9788dc9..056c6ec49 100755 --- a/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java @@ -378,4 +378,9 @@ public class HttpUtilTest { final HttpRequest request = HttpRequest.of(url).method(Method.GET); Console.log(request.execute().body()); } + + @Test + public void allowPatchTest() { + HttpGlobalConfig.allowPatch(); + } }