From 9e93485a97b55a5d71862f2c53c38c90a9386ac1 Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Wed, 17 Jul 2019 18:42:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EHttpRequest.getQueryBytes?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/net/http/HttpRequest.java | 14 ++++++++++++++ src/org/redkale/util/ByteArray.java | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/org/redkale/net/http/HttpRequest.java b/src/org/redkale/net/http/HttpRequest.java index d48a3cd8d..2c7fc48d1 100644 --- a/src/org/redkale/net/http/HttpRequest.java +++ b/src/org/redkale/net/http/HttpRequest.java @@ -42,6 +42,8 @@ public class HttpRequest extends Request { protected String requestURI; + private byte[] queryBytes; + private long contentLength = -1; private String contentType; @@ -120,9 +122,11 @@ public class HttpRequest extends Request { int qst = array.find(index, offset, (byte) '?'); if (qst > 0) { this.requestURI = array.toDecodeString(index, qst - index, charset).trim(); + this.queryBytes = array.getBytes(qst + 1, offset - qst - 1); addParameter(array, qst + 1, offset - qst - 1); } else { this.requestURI = array.toDecodeString(index, offset - index, charset).trim(); + this.queryBytes = new byte[0]; } index = ++offset; this.protocol = array.toString(index, array.size() - index, charset).trim(); @@ -488,6 +492,7 @@ public class HttpRequest extends Request { this.method = null; this.protocol = null; this.requestURI = null; + this.queryBytes = null; this.contentType = null; this.host = null; this.connection = null; @@ -667,6 +672,15 @@ public class HttpRequest extends Request { return requestURI; } + /** + * 获取请求参数的byte[] + * + * @return byte[] + */ + public byte[] getQueryBytes() { + return queryBytes; + } + /** * 截取getRequestURI最后的一个/后面的部分 * diff --git a/src/org/redkale/util/ByteArray.java b/src/org/redkale/util/ByteArray.java index d0684245e..8a894f2b1 100644 --- a/src/org/redkale/util/ByteArray.java +++ b/src/org/redkale/util/ByteArray.java @@ -142,6 +142,21 @@ public final class ByteArray { return Arrays.copyOf(content, count); } + /** + * 获取byte[] + * + * @param offset 偏移位 + * @param length 长度 + * + * @return byte[] + */ + public byte[] getBytes(int offset, int length) { + if (length < 1) return new byte[0]; + byte[] bs = new byte[length]; + System.arraycopy(this.content, offset, bs, 0, length); + return bs; + } + /** * 获取byte[]并清空 *