HttpRequest增加setFixedContentLength方法

This commit is contained in:
Looly 2024-09-14 15:31:22 +08:00
parent 975cfa0fb1
commit 277ecc90dc
2 changed files with 36 additions and 29 deletions

View File

@ -2,7 +2,7 @@
# 🚀Changelog # 🚀Changelog
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.8.33(2024-09-13) # 5.8.33(2024-09-14)
### 🐣新特性 ### 🐣新特性
* 【core 】 SyncFinisher增加setExecutorService方法issue#IANKQ1@Gitee * 【core 】 SyncFinisher增加setExecutorService方法issue#IANKQ1@Gitee
@ -11,7 +11,7 @@
* 【crypto 】 SM2解密时兼容GmSSL非压缩省略的04头的密文issue#IAP1QJ@Gitee * 【crypto 】 SM2解密时兼容GmSSL非压缩省略的04头的密文issue#IAP1QJ@Gitee
* 【core 】 兼容NumberUtil.add方法传入整型自动类型转换为浮点类型的精度丢失问题pr#3721@Github * 【core 】 兼容NumberUtil.add方法传入整型自动类型转换为浮点类型的精度丢失问题pr#3721@Github
* 【core 】 ModifierUtil明确注释并增加hasAllModifiers方法issue#IAQ2U0@Gitee * 【core 】 ModifierUtil明确注释并增加hasAllModifiers方法issue#IAQ2U0@Gitee
* 【http 】 HttpRequest增加setFixedLengthStreamingMode方法issue#3462@Github * 【http 】 HttpRequest增加setFixedContentLength方法issue#3462@Github
### 🐞Bug修复 ### 🐞Bug修复
* 【json 】 修复JSONConfig.setDateFormat设置后toBean无效问题issue#3713@Github * 【json 】 修复JSONConfig.setDateFormat设置后toBean无效问题issue#3713@Github

View File

@ -238,6 +238,10 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 重定向次数计数器内部使用 * 重定向次数计数器内部使用
*/ */
private int redirectCount; private int redirectCount;
/**
* 固定长度用于设置HttpURLConnection.setFixedLengthStreamingMode默认为0表示使用默认值默认值由HttpURLConnection内部决定通常为0
*/
private long fixedContentLength;
/** /**
* 构造URL编码默认使用UTF-8 * 构造URL编码默认使用UTF-8
@ -358,8 +362,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* @return this * @return this
* @since 5.8.33 * @since 5.8.33
*/ */
public HttpRequest setFixedLengthStreamingMode(long contentLength){ public HttpRequest setFixedContentLength(long contentLength) {
this.httpConnection.setFixedLengthStreamingMode(contentLength); this.fixedContentLength = contentLength;
return this; return this;
} }
@ -878,6 +882,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
/** /**
* 自动重定向时是否处理cookie * 自动重定向时是否处理cookie
*
* @param followRedirectsCookie 自动重定向时是否处理cookie * @param followRedirectsCookie 自动重定向时是否处理cookie
* @return this * @return this
*/ */
@ -1239,6 +1244,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
.setInstanceFollowRedirects(false) .setInstanceFollowRedirects(false)
// 流方式上传数据 // 流方式上传数据
.setChunkedStreamingMode(config.blockSize) .setChunkedStreamingMode(config.blockSize)
// issue#3462 自定义body长度
.setFixedLengthStreamingMode(this.fixedContentLength)
// 覆盖默认Header // 覆盖默认Header
.header(this.headers, false); .header(this.headers, false);