新增HttpRequest.getQueryBytes方法
This commit is contained in:
@@ -42,6 +42,8 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
|
||||
protected String requestURI;
|
||||
|
||||
private byte[] queryBytes;
|
||||
|
||||
private long contentLength = -1;
|
||||
|
||||
private String contentType;
|
||||
@@ -120,9 +122,11 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
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<HttpContext> {
|
||||
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<HttpContext> {
|
||||
return requestURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求参数的byte[]
|
||||
*
|
||||
* @return byte[]
|
||||
*/
|
||||
public byte[] getQueryBytes() {
|
||||
return queryBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取getRequestURI最后的一个/后面的部分
|
||||
*
|
||||
|
||||
@@ -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[]并清空
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user