From 5a2dbc4e67606e51fa917809cc8681834508db1e Mon Sep 17 00:00:00 2001 From: redkale Date: Thu, 15 Aug 2024 18:08:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0chunked=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/redkale/net/http/HttpRequest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/org/redkale/net/http/HttpRequest.java b/src/main/java/org/redkale/net/http/HttpRequest.java index c8db266aa..09da0c6a1 100644 --- a/src/main/java/org/redkale/net/http/HttpRequest.java +++ b/src/main/java/org/redkale/net/http/HttpRequest.java @@ -74,6 +74,8 @@ public class HttpRequest extends Request { protected static final String HEAD_CONTENT_LENGTH = "Content-Length"; + protected static final String HEAD_TRANSFER_ENCODING = "Transfer-Encoding"; + protected static final String HEAD_ACCEPT = "Accept"; protected static final String HEAD_HOST = "Host"; @@ -141,6 +143,8 @@ public class HttpRequest extends Request { protected final HttpParameters params = HttpParameters.create(); + protected boolean chunked = false; + protected boolean boundary = false; protected int moduleid; @@ -837,6 +841,17 @@ public class HttpRequest extends Request { && content[8] == 't'; headers.setValid(HEAD_UPGRADE, this.maybews ? "websocket" : bytes.toString(true, charset)); break; + case HEAD_TRANSFER_ENCODING: // Transfer-Encoding + this.chunked = vlen == 7 + && content[0] == 'c' + && content[1] == 'h' + && content[2] == 'u' + && content[3] == 'n' + && content[4] == 'k' + && content[5] == 'e' + && content[6] == 'd'; + headers.setValid(HEAD_TRANSFER_ENCODING, this.chunked ? "chunked" : bytes.toString(true, charset)); + break; case HEAD_EXPECT: // Expect this.expect = vlen == 12 && content[0] == '1' @@ -928,6 +943,25 @@ public class HttpRequest extends Request { if (bs[1] == 'c' && bs[2] == 'c' && bs[3] == 'e' && bs[4] == 'p' && bs[5] == 't') { return HEAD_ACCEPT; } + } else if ((first == 'T' || first == 't') && size == 17) { // Transfer-Encoding + if (bs[1] == 'r' + && bs[2] == 'a' + && bs[3] == 'n' + && bs[4] == 's' + && bs[5] == 'f' + && bs[6] == 'e' + && bs[7] == 'r' + && bs[8] == '-' + && (bs[9] == 'E' || bs[9] == 'e') + && bs[10] == 'n' + && bs[11] == 'c' + && bs[12] == 'o' + && bs[13] == 'd' + && bs[14] == 'i' + && bs[15] == 'n' + && bs[16] == 'g') { + return HEAD_TRANSFER_ENCODING; + } } else if (first == 'C' || first == 'c') { if (size == 10) { // Connection if (bs[1] == 'o' @@ -1072,6 +1106,7 @@ public class HttpRequest extends Request { this.requestPath = null; this.queryBytes = null; this.boundary = false; + this.chunked = false; this.bodyParsed = false; this.moduleid = 0; this.actionid = 0;