mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
add config
This commit is contained in:
parent
186d58396e
commit
87fd7393f9
@ -41,6 +41,10 @@ public class HttpGlobalConfig implements Serializable {
|
||||
private static int maxRedirectCount = 0;
|
||||
private static boolean ignoreEOFError = true;
|
||||
private static boolean decodeUrl = false;
|
||||
/**
|
||||
* 是否从响应正文中的meta标签获取编码信息
|
||||
*/
|
||||
private static boolean getCharsetFromContent = true;
|
||||
|
||||
/**
|
||||
* 获取全局默认的超时时长
|
||||
@ -187,4 +191,24 @@ public class HttpGlobalConfig implements Serializable {
|
||||
synchronized public static void closeCookie() {
|
||||
GlobalCookieManager.setCookieManager(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否从响应正文中的meta标签获取编码信息
|
||||
*
|
||||
* @param customGetCharsetFromContent 是否从响应正文中的meta标签获取编码信息
|
||||
* @since 6.0.0
|
||||
*/
|
||||
synchronized public static void setGetCharsetFromContent(final boolean customGetCharsetFromContent){
|
||||
getCharsetFromContent = customGetCharsetFromContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否从响应正文中的meta标签获取编码信息
|
||||
*
|
||||
* @return 是否从响应正文中的meta标签获取编码信息
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static boolean isGetCharsetFromContent(){
|
||||
return getCharsetFromContent;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import org.dromara.hutool.core.regex.ReUtil;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
import org.dromara.hutool.http.HttpException;
|
||||
import org.dromara.hutool.http.HttpGlobalConfig;
|
||||
import org.dromara.hutool.http.client.Response;
|
||||
import org.dromara.hutool.http.html.HtmlUtil;
|
||||
import org.dromara.hutool.http.meta.HeaderName;
|
||||
@ -98,7 +99,7 @@ public class ResponseBody implements HttpBody, Closeable {
|
||||
* @return 响应字符串
|
||||
*/
|
||||
public String getString() {
|
||||
return HtmlUtil.getString(getBytes(), response.charset(), true);
|
||||
return HtmlUtil.getString(getBytes(), response.charset(), HttpGlobalConfig.isGetCharsetFromContent());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +76,8 @@ public class JdkHttpResponse implements Response, Closeable {
|
||||
* @param isAsync 是否异步
|
||||
* @param isIgnoreBody 是否忽略读取响应体
|
||||
*/
|
||||
protected JdkHttpResponse(final JdkHttpConnection httpConnection, final boolean ignoreEOFError, final Charset requestCharset, final boolean isAsync, final boolean isIgnoreBody) {
|
||||
protected JdkHttpResponse(final JdkHttpConnection httpConnection, final boolean ignoreEOFError,
|
||||
final Charset requestCharset, final boolean isAsync, final boolean isIgnoreBody) {
|
||||
this.httpConnection = httpConnection;
|
||||
this.ignoreEOFError = ignoreEOFError;
|
||||
this.requestCharset = requestCharset;
|
||||
|
Loading…
Reference in New Issue
Block a user