mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
HttpRequest增加setFixedContentLength方法
This commit is contained in:
parent
975cfa0fb1
commit
277ecc90dc
@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.33(2024-09-13)
|
||||
# 5.8.33(2024-09-14)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 SyncFinisher增加setExecutorService方法(issue#IANKQ1@Gitee)
|
||||
@ -11,7 +11,7 @@
|
||||
* 【crypto 】 SM2解密时,兼容GmSSL非压缩省略的04头的密文(issue#IAP1QJ@Gitee)
|
||||
* 【core 】 兼容NumberUtil.add方法传入整型自动类型转换为浮点类型的精度丢失问题(pr#3721@Github)
|
||||
* 【core 】 ModifierUtil明确注释,并增加hasAllModifiers方法(issue#IAQ2U0@Gitee)
|
||||
* 【http 】 HttpRequest增加setFixedLengthStreamingMode方法(issue#3462@Github)
|
||||
* 【http 】 HttpRequest增加setFixedContentLength方法(issue#3462@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【json 】 修复JSONConfig.setDateFormat设置后toBean无效问题(issue#3713@Github)
|
||||
|
@ -238,6 +238,10 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 重定向次数计数器,内部使用
|
||||
*/
|
||||
private int redirectCount;
|
||||
/**
|
||||
* 固定长度,用于设置HttpURLConnection.setFixedLengthStreamingMode,默认为0,表示使用默认值,默认值由HttpURLConnection内部决定,通常为0
|
||||
*/
|
||||
private long fixedContentLength;
|
||||
|
||||
/**
|
||||
* 构造,URL编码默认使用UTF-8
|
||||
@ -358,8 +362,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 5.8.33
|
||||
*/
|
||||
public HttpRequest setFixedLengthStreamingMode(long contentLength){
|
||||
this.httpConnection.setFixedLengthStreamingMode(contentLength);
|
||||
public HttpRequest setFixedContentLength(long contentLength) {
|
||||
this.fixedContentLength = contentLength;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -878,6 +882,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
|
||||
/**
|
||||
* 自动重定向时是否处理cookie
|
||||
*
|
||||
* @param followRedirectsCookie 自动重定向时是否处理cookie
|
||||
* @return this
|
||||
*/
|
||||
@ -1239,6 +1244,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
.setInstanceFollowRedirects(false)
|
||||
// 流方式上传数据
|
||||
.setChunkedStreamingMode(config.blockSize)
|
||||
// issue#3462 自定义body长度
|
||||
.setFixedLengthStreamingMode(this.fixedContentLength)
|
||||
// 覆盖默认Header
|
||||
.header(this.headers, false);
|
||||
|
||||
@ -1392,7 +1399,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
*
|
||||
* @return body
|
||||
*/
|
||||
private RequestBody createBody(){
|
||||
private RequestBody createBody() {
|
||||
// Write的时候会优先使用body中的内容,write时自动关闭OutputStream
|
||||
if (null != this.body) {
|
||||
return ResourceBody.create(this.body);
|
||||
@ -1410,9 +1417,9 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
private void sendMultipart() throws IOException {
|
||||
final RequestBody body;
|
||||
// issue#3158,当用户自定义为multipart同时传入body,则不做单独处理
|
||||
if(null == form && null != this.body) {
|
||||
if (null == form && null != this.body) {
|
||||
body = ResourceBody.create(this.body);
|
||||
}else{
|
||||
} else {
|
||||
final MultipartBody multipartBody = MultipartBody.create(this.form, this.charset);
|
||||
//设置表单类型为Multipart(文件上传)
|
||||
this.httpConnection.header(Header.CONTENT_TYPE, multipartBody.getContentType(), true);
|
||||
|
Loading…
Reference in New Issue
Block a user