mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add method
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user