This commit is contained in:
Looly 2024-03-12 11:32:40 +08:00
parent 8a19e12f92
commit e054a80b16
2 changed files with 22 additions and 1 deletions

View File

@ -45,6 +45,7 @@ public class HttpGlobalConfig implements Serializable {
* 是否从响应正文中的meta标签获取编码信息
*/
private static boolean getCharsetFromContent = true;
private static boolean trustAnyHost = false;
/**
* 获取全局默认的超时时长
@ -211,4 +212,24 @@ public class HttpGlobalConfig implements Serializable {
public static boolean isGetCharsetFromContent(){
return getCharsetFromContent;
}
/**
* 是否信任所有Host
* @return 是否信任所有Host
* @since 5.8.27
*/
public static boolean isTrustAnyHost(){
return trustAnyHost;
}
/**
* 是否信任所有Host<br>
* https://github.com/dromara/hutool/issues/2042<br>
*
* @param customTrustAnyHost 如果设置为{@code false}则按照JDK默认验证机制验证目标服务器的证书host和请求host是否一致{@code true}表示不验证
* @since 5.8.27
*/
public static void setTrustAnyHost(boolean customTrustAnyHost) {
trustAnyHost = customTrustAnyHost;
}
}

View File

@ -59,7 +59,7 @@ public class ClientConfig {
public ClientConfig() {
connectionTimeout = HttpGlobalConfig.getTimeout();
readTimeout = HttpGlobalConfig.getTimeout();
sslInfo = SSLInfo.TRUST_ANY;
sslInfo = HttpGlobalConfig.isTrustAnyHost() ? SSLInfo.TRUST_ANY : SSLInfo.DEFAULT;
}
/**