This commit is contained in:
@@ -16,12 +16,7 @@ import org.redkale.util.AnyValue.DefaultAnyValue;
|
|||||||
import org.redkale.util.ByteArray;
|
import org.redkale.util.ByteArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Http请求包 与javax.servlet.http.HttpServletRequest 基本类似。
|
* Http请求包 与javax.servlet.http.HttpServletRequest 基本类似。 同时提供json的解析接口: public Object getJsonParameter(Class clazz, String name) RedKale提倡带简单的参数的GET请求采用类似REST风格, 因此提供了 getRequstURIPath 系列接口。 例如简单的翻页查询 /pipes/record/query/page:2/size:20 获取页号: int page = request.getRequstURIPath("page:", 1); 获取行数: int size = request.getRequstURIPath("size:", 10);
|
||||||
* 同时提供json的解析接口: public Object getJsonParameter(Class clazz, String name)
|
|
||||||
* RedKale提倡带简单的参数的GET请求采用类似REST风格, 因此提供了 getRequstURIPath 系列接口。
|
|
||||||
* 例如简单的翻页查询 /pipes/record/query/page:2/size:20
|
|
||||||
* 获取页号: int page = request.getRequstURIPath("page:", 1);
|
|
||||||
* 获取行数: int size = request.getRequstURIPath("size:", 10);
|
|
||||||
* <p>
|
* <p>
|
||||||
* <p>
|
* <p>
|
||||||
* 详情见: http://redkale.org
|
* 详情见: http://redkale.org
|
||||||
@@ -168,6 +163,10 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
protected void prepare() {
|
protected void prepare() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void skipBodyParse() {
|
||||||
|
this.bodyparsed = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void parseBody() {
|
private void parseBody() {
|
||||||
if (this.boundary || bodyparsed) return;
|
if (this.boundary || bodyparsed) return;
|
||||||
addParameter(array, 0, array.size());
|
addParameter(array, 0, array.size());
|
||||||
@@ -235,8 +234,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取客户端地址IP, 与getRemoteAddres() 的区别在于:本方法优先取header中指定为RemoteAddress名的值,没有则返回getRemoteAddres()的getHostAddress()。
|
* 获取客户端地址IP, 与getRemoteAddres() 的区别在于:本方法优先取header中指定为RemoteAddress名的值,没有则返回getRemoteAddres()的getHostAddress()。 本方法适用于服务前端有如nginx的代理服务器进行中转,通过getRemoteAddres()是获取不到客户端的真实IP。
|
||||||
* 本方法适用于服务前端有如nginx的代理服务器进行中转,通过getRemoteAddres()是获取不到客户端的真实IP。
|
|
||||||
*
|
*
|
||||||
* @return 地址
|
* @return 地址
|
||||||
*/
|
*/
|
||||||
@@ -493,9 +491,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求URL分段中含prefix段的值
|
* 获取请求URL分段中含prefix段的值 例如请求URL /pipes/record/query/name:hello 获取name参数: String name = request.getRequstURIPath("name:", "none");
|
||||||
* 例如请求URL /pipes/record/query/name:hello
|
|
||||||
* 获取name参数: String name = request.getRequstURIPath("name:", "none");
|
|
||||||
*
|
*
|
||||||
* @param prefix prefix段前缀
|
* @param prefix prefix段前缀
|
||||||
* @param defvalue 默认值
|
* @param defvalue 默认值
|
||||||
@@ -511,9 +507,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求URL分段中含prefix段的short值
|
* 获取请求URL分段中含prefix段的short值 例如请求URL /pipes/record/query/type:10 获取type参数: short type = request.getRequstURIPath("type:", (short)0);
|
||||||
* 例如请求URL /pipes/record/query/type:10
|
|
||||||
* 获取type参数: short type = request.getRequstURIPath("type:", (short)0);
|
|
||||||
*
|
*
|
||||||
* @param prefix prefix段前缀
|
* @param prefix prefix段前缀
|
||||||
* @param defvalue 默认short值
|
* @param defvalue 默认short值
|
||||||
@@ -525,10 +519,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求URL分段中含prefix段的int值
|
* 获取请求URL分段中含prefix段的int值 例如请求URL /pipes/record/query/page:2/size:50 获取page参数: int page = request.getRequstURIPath("page:", 1); 获取size参数: int size = request.getRequstURIPath("size:", 20);
|
||||||
* 例如请求URL /pipes/record/query/page:2/size:50
|
|
||||||
* 获取page参数: int page = request.getRequstURIPath("page:", 1);
|
|
||||||
* 获取size参数: int size = request.getRequstURIPath("size:", 20);
|
|
||||||
*
|
*
|
||||||
* @param prefix prefix段前缀
|
* @param prefix prefix段前缀
|
||||||
* @param defvalue 默认int值
|
* @param defvalue 默认int值
|
||||||
@@ -540,9 +531,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求URL分段中含prefix段的long值
|
* 获取请求URL分段中含prefix段的long值 例如请求URL /pipes/record/query/time:1453104341363/id:40 获取time参数: long time = request.getRequstURIPath("time:", 0L);
|
||||||
* 例如请求URL /pipes/record/query/time:1453104341363/id:40
|
|
||||||
* 获取time参数: long time = request.getRequstURIPath("time:", 0L);
|
|
||||||
*
|
*
|
||||||
* @param prefix prefix段前缀
|
* @param prefix prefix段前缀
|
||||||
* @param defvalue 默认long值
|
* @param defvalue 默认long值
|
||||||
@@ -641,7 +630,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
* @return header值
|
* @return header值
|
||||||
*/
|
*/
|
||||||
public short getShortHeader(String name, int defaultValue) {
|
public short getShortHeader(String name, int defaultValue) {
|
||||||
return header.getShortValue(name, (short)defaultValue);
|
return header.getShortValue(name, (short) defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -782,7 +771,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
*/
|
*/
|
||||||
public short getShortParameter(String name, int defaultValue) {
|
public short getShortParameter(String name, int defaultValue) {
|
||||||
parseBody();
|
parseBody();
|
||||||
return params.getShortValue(name, (short)defaultValue);
|
return params.getShortValue(name, (short) defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -67,6 +67,20 @@ public final class ByteArray {
|
|||||||
System.arraycopy(this.content, 0, buf, 0, count);
|
System.arraycopy(this.content, 0, buf, 0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void directFrom(ByteArray array) {
|
||||||
|
if (array != null) {
|
||||||
|
this.content = array.content;
|
||||||
|
this.count = array.count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void directTo(ByteArray array) {
|
||||||
|
if (array != null) {
|
||||||
|
array.content = this.content;
|
||||||
|
array.count = this.count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] directBytes() {
|
public byte[] directBytes() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user