diff --git a/CHANGELOG.md b/CHANGELOG.md index 028f89a51..a348aabc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ## 4.6.4 ### 新特性 +* 【http】 自动关闭HttpURLConnection的头安全检查(issue#512@Github) +* 【setting】 Setting变量替换支持从系统参数中取值 ### Bug修复 * 【db】 解决ThreadLocalConnection多数据源被移除问题(pr#66@Gitee) diff --git a/hutool-http/src/main/java/cn/hutool/http/GlobalHeaders.java b/hutool-http/src/main/java/cn/hutool/http/GlobalHeaders.java index 10f1e88e1..6c933ab13 100644 --- a/hutool-http/src/main/java/cn/hutool/http/GlobalHeaders.java +++ b/hutool-http/src/main/java/cn/hutool/http/GlobalHeaders.java @@ -37,6 +37,10 @@ public enum GlobalHeaders { * @return this */ public GlobalHeaders putDefault(boolean isReset) { + // 解决HttpURLConnection中无法自定义Host等头信息的问题 + // https://stackoverflow.com/questions/9096987/how-to-overwrite-http-header-host-in-a-httpurlconnection/9098440 + System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); + if (isReset) { this.headers.clear(); } diff --git a/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java b/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java index c416836a6..8706baee5 100644 --- a/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java +++ b/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java @@ -201,22 +201,23 @@ public class SettingLoader { for (String var : vars) { key = ReUtil.get(reg_var, var, 1); if (StrUtil.isNotBlank(key)) { - // 查找变量名对应的值 + // 本分组中查找变量名对应的值 String varValue = this.groupedMap.get(group, key); - if (null != varValue) { - // 替换标识 - value = value.replace(var, varValue); - } else { - // 跨分组查找 + // 跨分组查找 + if (null == varValue) { final List groupAndKey = StrUtil.split(key, CharUtil.DOT, 2); if (groupAndKey.size() > 1) { varValue = this.groupedMap.get(groupAndKey.get(0), groupAndKey.get(1)); - if (null != varValue) { - // 替换标识 - value = value.replace(var, varValue); - } } } + // 系统参数中查找 + if(null == varValue) { + varValue = System.getProperty(key); + } + if (null != varValue) { + // 替换标识 + value = value.replace(var, varValue); + } } } return value;