mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-02 20:02:49 +08:00
add setChunkedStreamingMode method
This commit is contained in:
parent
7ca33d1602
commit
d3fff05b95
@ -15,6 +15,7 @@
|
||||
* 【json】 添加自定义序列化反序列化支持(issue#I1052A@Gitee)
|
||||
* 【dfa】 优化特殊字符构建,优化查找,改为使用StrBuilder
|
||||
* 【core】 ZipUtil增加FileFilter参数的重载,支持文件过滤(issue#I11RTP@Gitee)
|
||||
* 【http】 HttpRequest增加setChunkedStreamingMode方法(issue#525@Github)
|
||||
|
||||
### Bug修复
|
||||
* 【core】 修复NetUtil.getUsableLocalPort问题(pr#69@Gitee)
|
||||
|
@ -349,11 +349,13 @@ public class HttpConnection {
|
||||
* 采用流方式上传数据,无需本地缓存数据。<br>
|
||||
* HttpUrlConnection默认是将所有数据读到本地缓存,然后再发送给服务器,这样上传大文件时就会导致内存溢出。
|
||||
*
|
||||
* @param blockSize 块大小(bytes数)
|
||||
* @param blockSize 块大小(bytes数),0或小于0表示不设置Chuncked模式
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setChunkedStreamingMode(int blockSize) {
|
||||
conn.setChunkedStreamingMode(blockSize);
|
||||
if(blockSize > 0) {
|
||||
conn.setChunkedStreamingMode(blockSize);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
private int redirectCount;
|
||||
/** 最大重定向次数 */
|
||||
private int maxRedirectCount;
|
||||
/** Chuncked块大小,0或小于0表示不设置Chuncked模式 */
|
||||
private int blockSize;
|
||||
/** 代理 */
|
||||
private Proxy proxy;
|
||||
|
||||
@ -857,6 +859,19 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
this.isRest = isRest;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 采用流方式上传数据,无需本地缓存数据。<br>
|
||||
* HttpUrlConnection默认是将所有数据读到本地缓存,然后再发送给服务器,这样上传大文件时就会导致内存溢出。
|
||||
*
|
||||
* @param blockSize 块大小(bytes数),0或小于0表示不设置Chuncked模式
|
||||
* @return this
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public HttpRequest setChunkedStreamingMode(int blockSize) {
|
||||
this.blockSize = blockSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行Reuqest请求
|
||||
@ -946,6 +961,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
.setCookie(this.cookie)
|
||||
// 定义转发
|
||||
.setInstanceFollowRedirects(this.maxRedirectCount > 0 ? true : false)
|
||||
// 流方式上传数据
|
||||
.setChunkedStreamingMode(this.blockSize)
|
||||
// 覆盖默认Header
|
||||
.header(this.headers, true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user