修复graalvm编译后,未读取Content-Length可能导致的读取时间过长问题

This commit is contained in:
Looly
2023-12-12 23:04:27 +08:00
parent b8f3529238
commit d46f00d2be
2 changed files with 20 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package cn.hutool.http.server;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.LimitedInputStream;
import cn.hutool.core.map.CaseInsensitiveMap;
import cn.hutool.core.map.multi.ListValueMap;
import cn.hutool.core.net.NetUtil;
@@ -294,7 +295,24 @@ public class HttpServerRequest extends HttpServerBase {
* @return 流
*/
public InputStream getBodyStream() {
return this.httpExchange.getRequestBody();
InputStream bodyStream = this.httpExchange.getRequestBody();
//issue#I6Q30X读取body长度避免读取结束后无法正常结束问题
final String contentLengthStr = getHeader(Header.CONTENT_LENGTH);
long contentLength = 0;
if(StrUtil.isNotBlank(contentLengthStr)){
try{
contentLength = Long.parseLong(contentLengthStr);
} catch (final NumberFormatException ignore){
// ignore
}
}
if(contentLength > 0){
bodyStream = new LimitedInputStream(bodyStream, contentLength);
}
return bodyStream;
}
/**