From 115f91b64acafaa171c8d3debc65098f4f08c50a Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Sat, 4 Aug 2018 18:31:29 +0800 Subject: [PATCH] --- src/org/redkale/net/http/HttpRequest.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/org/redkale/net/http/HttpRequest.java b/src/org/redkale/net/http/HttpRequest.java index 7193bd425..bba000486 100644 --- a/src/org/redkale/net/http/HttpRequest.java +++ b/src/org/redkale/net/http/HttpRequest.java @@ -165,19 +165,18 @@ public class HttpRequest extends Request { header.addValue(name, value); } } - array.clear(); - - if (buffer.hasRemaining()) array.write(buffer, buffer.remaining()); - - if (this.contentType != null && this.contentType.contains("boundary=")) { - this.boundary = true; - } + if (this.contentType != null && this.contentType.contains("boundary=")) this.boundary = true; if (this.boundary) this.keepAlive = false; //文件上传必须设置keepAlive为false,因为文件过大时用户不一定会skip掉多余的数据 + + array.clear(); if (this.contentLength > 0 && (this.contentType == null || !this.boundary)) { if (this.contentLength > context.getMaxbody()) return -1; + array.write(buffer, Math.min((int) this.contentLength, buffer.remaining())); int lr = (int) this.contentLength - array.size(); return lr > 0 ? lr : 0; } + if (buffer.hasRemaining() && (this.boundary || !this.keepAlive)) array.write(buffer, buffer.remaining()); //文件上传、HTTP1.0或Connection:close + //暂不考虑是keep-alive且存在body却没有指定Content-Length的情况 return 0; }