mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
add method
This commit is contained in:
parent
749c0f8727
commit
15a34bcc24
@ -13,6 +13,7 @@
|
||||
* 【core 】 ObjectUtil 添加三个defaultIfXxxx方法,用于节省CPU及内存损耗(pr#2094@Github)
|
||||
* 【db 】 增加单条数据原生upsert语义支持(pr#501@Gitee)
|
||||
* 【core 】 在CollectorUtil提交Collectors.toMap的对null友好实现,避免NPE(pr#502@Gitee)
|
||||
* 【http 】 增加HttpGlobalConfig.setIgnoreEOFError(issue#2092@Github)
|
||||
*
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复setter重载导致匹配错误(issue#2082@Github)
|
||||
|
@ -32,6 +32,7 @@ public class HttpGlobalConfig implements Serializable {
|
||||
private static boolean isAllowPatch = false;
|
||||
private static String boundary = "--------------------Hutool_" + RandomUtil.randomString(16);
|
||||
private static int maxRedirectCount = 0;
|
||||
private static boolean ignoreEOFError = true;
|
||||
|
||||
/**
|
||||
* 获取全局默认的超时时长
|
||||
@ -99,6 +100,30 @@ public class HttpGlobalConfig implements Serializable {
|
||||
maxRedirectCount = customMaxRedirectCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取是否忽略响应读取时可能的EOF异常。<br>
|
||||
* 在Http协议中,对于Transfer-Encoding: Chunked在正常情况下末尾会写入一个Length为0的的chunk标识完整结束。<br>
|
||||
* 如果服务端未遵循这个规范或响应没有正常结束,会报EOF异常,此选项用于是否忽略这个异常。
|
||||
*
|
||||
* @return 是否忽略响应读取时可能的EOF异常
|
||||
* @since 5.7.20
|
||||
*/
|
||||
public static boolean isIgnoreEOFError() {
|
||||
return ignoreEOFError;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否忽略响应读取时可能的EOF异常。<br>
|
||||
* 在Http协议中,对于Transfer-Encoding: Chunked在正常情况下末尾会写入一个Length为0的的chunk标识完整结束。<br>
|
||||
* 如果服务端未遵循这个规范或响应没有正常结束,会报EOF异常,此选项用于是否忽略这个异常。
|
||||
*
|
||||
* @param customIgnoreEOFError 是否忽略响应读取时可能的EOF异常。
|
||||
* @since 5.7.20
|
||||
*/
|
||||
synchronized public static void setIgnoreEOFError(boolean customIgnoreEOFError) {
|
||||
ignoreEOFError = customIgnoreEOFError;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Cookie管理器,用于自定义Cookie管理
|
||||
*
|
||||
|
@ -588,7 +588,8 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
copyLength = IoUtil.copy(in, out, IoUtil.DEFAULT_BUFFER_SIZE, contentLength, streamProgress);
|
||||
} catch (IORuntimeException e) {
|
||||
//noinspection StatementWithEmptyBody
|
||||
if (e.getCause() instanceof EOFException || StrUtil.containsIgnoreCase(e.getMessage(), "Premature EOF")) {
|
||||
if (HttpGlobalConfig.isIgnoreEOFError()
|
||||
&& (e.getCause() instanceof EOFException || StrUtil.containsIgnoreCase(e.getMessage(), "Premature EOF"))) {
|
||||
// 忽略读取HTTP流中的EOF错误
|
||||
} else {
|
||||
throw e;
|
||||
|
Loading…
Reference in New Issue
Block a user