mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
HttpConfig
增加参数setIgnoreContentLength
可选忽略读取响应contentLength头(issue#ICB1B8@Gitee)
This commit is contained in:
parent
fe597605cf
commit
2c8070f324
@ -8,6 +8,7 @@
|
|||||||
* 【ai 】 增加SSE流式返回函数参数callback,豆包、grok新增文生图接口,豆包生成视频支持使用model
|
* 【ai 】 增加SSE流式返回函数参数callback,豆包、grok新增文生图接口,豆包生成视频支持使用model
|
||||||
* 【core 】 DesensitizedUtil新增护照号码脱敏功能(pr#1347@Gitee)
|
* 【core 】 DesensitizedUtil新增护照号码脱敏功能(pr#1347@Gitee)
|
||||||
* 【core 】 优化XXXToMapCopier的部分性能(pr#1345@Gitee)
|
* 【core 】 优化XXXToMapCopier的部分性能(pr#1345@Gitee)
|
||||||
|
* 【http 】 `HttpConfig`增加参数`setIgnoreContentLength`可选忽略读取响应contentLength头(issue#ICB1B8@Gitee)
|
||||||
*
|
*
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复`NumberUtil`isNumber方法以L结尾没有小数点判断问题(issue#3938@Github)
|
* 【core 】 修复`NumberUtil`isNumber方法以L结尾没有小数点判断问题(issue#3938@Github)
|
||||||
|
@ -101,6 +101,12 @@ public class HttpConfig {
|
|||||||
*/
|
*/
|
||||||
boolean useDefaultContentTypeIfNull = true;
|
boolean useDefaultContentTypeIfNull = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否忽略Content-Length,如果为true,则忽略Content-Length,自动根据响应内容计算Content-Length<br>
|
||||||
|
* issue#ICB1B8@Gitee,此参数主要解决服务端响应中Content-Length错误的问题
|
||||||
|
*/
|
||||||
|
boolean ignoreContentLength = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置超时,单位:毫秒<br>
|
* 设置超时,单位:毫秒<br>
|
||||||
* 超时包括:
|
* 超时包括:
|
||||||
@ -332,4 +338,15 @@ public class HttpConfig {
|
|||||||
this.useDefaultContentTypeIfNull = useDefaultContentTypeIfNull;
|
this.useDefaultContentTypeIfNull = useDefaultContentTypeIfNull;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置是否忽略Content-Length,如果为true,则忽略Content-Length,自动根据响应内容计算Content-Length
|
||||||
|
* @param ignoreContentLength 是否忽略Content-Length
|
||||||
|
* @return this
|
||||||
|
* @since 5.8.39
|
||||||
|
*/
|
||||||
|
public HttpConfig setIgnoreContentLength(boolean ignoreContentLength) {
|
||||||
|
this.ignoreContentLength = ignoreContentLength;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -664,7 +664,8 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final long contentLength = contentLength();
|
// issue#ICB1B8,如果用户定义忽略contentLength头,则不读取
|
||||||
|
final long contentLength = config.ignoreContentLength ? -1 : contentLength();
|
||||||
final FastByteArrayOutputStream out = new FastByteArrayOutputStream((int) contentLength);
|
final FastByteArrayOutputStream out = new FastByteArrayOutputStream((int) contentLength);
|
||||||
copyBody(in, out, contentLength, null, this.config.ignoreEOFError);
|
copyBody(in, out, contentLength, null, this.config.ignoreEOFError);
|
||||||
this.body = new BytesResource(out.toByteArray());
|
this.body = new BytesResource(out.toByteArray());
|
||||||
|
Loading…
Reference in New Issue
Block a user