add method

This commit is contained in:
Looly 2022-01-15 22:09:52 +08:00
parent 749c0f8727
commit 15a34bcc24
3 changed files with 28 additions and 1 deletions

View File

@ -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

View File

@ -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管理
*

View File

@ -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;