From 72fda8c33649f345b9f53974f69f104f84589489 Mon Sep 17 00:00:00 2001 From: wentch <22250530@qq.com> Date: Tue, 19 Jan 2016 10:38:18 +0800 Subject: [PATCH] --- src/org/redkale/net/http/HttpRequest.java | 153 +++++++++++----------- 1 file changed, 77 insertions(+), 76 deletions(-) diff --git a/src/org/redkale/net/http/HttpRequest.java b/src/org/redkale/net/http/HttpRequest.java index 7a1ef1e03..3a14c56e9 100644 --- a/src/org/redkale/net/http/HttpRequest.java +++ b/src/org/redkale/net/http/HttpRequest.java @@ -224,6 +224,15 @@ public class HttpRequest extends Request { super.removeProperty(name); } + /** + * 获取客户端地址IP + * + * @return 地址 + */ + public SocketAddress getRemoteAddress() { + return this.channel.getRemoteAddress(); + } + /** * 获取客户端地址IP, 与getRemoteAddres() 的区别在于:本方法优先取header中指定为RemoteAddress名的值,没有则返回getRemoteAddres()的getHostAddress()。 * 本方法适用于服务前端有如nginx的代理服务器进行中转,通过getRemoteAddres()是获取不到客户端的真实IP。 @@ -260,15 +269,6 @@ public class HttpRequest extends Request { return array.toString(UTF8); } - /** - * 获取客户端地址IP - * - * @return 地址 - */ - public SocketAddress getRemoteAddress() { - return this.channel.getRemoteAddress(); - } - @Override public String toString() { parseBody(); @@ -278,16 +278,6 @@ public class HttpRequest extends Request { + ", host:" + this.host + ", params:" + this.params + ", header:" + this.header + "}"; } - /** - * 获取文件上传信息列表 - * - * @return 文件上传对象集合 - * @throws IOException IO异常 - */ - public final Iterable multiParts() throws IOException { - return getMultiContext().parts(); - } - /** * 获取文件上传对象 * @@ -303,6 +293,16 @@ public class HttpRequest extends Request { }, null); } + /** + * 获取文件上传信息列表 + * + * @return 文件上传对象集合 + * @throws IOException IO异常 + */ + public final Iterable multiParts() throws IOException { + return getMultiContext().parts(); + } + @Override protected void recycle() { this.cookiestr = null; @@ -407,12 +407,12 @@ public class HttpRequest extends Request { } /** - * 获取Connection的Header值 + * 获取协议名 http、https、ws、wss等 * - * @return Connection + * @return protocol */ - public String getConnection() { - return connection; + public String getProtocol() { + return protocol; } /** @@ -425,12 +425,30 @@ public class HttpRequest extends Request { } /** - * 获取协议名 http、https、ws、wss等 + * 获取Content-Type的header值 * - * @return protocol + * @return contentType */ - public String getProtocol() { - return protocol; + public String getContentType() { + return contentType; + } + + /** + * 获取请求内容的长度, 为-1表示内容长度不确定 + * + * @return 内容长度 + */ + public long getContentLength() { + return contentLength; + } + + /** + * 获取Connection的Header值 + * + * @return Connection + */ + public String getConnection() { + return connection; } /** @@ -442,6 +460,15 @@ public class HttpRequest extends Request { return host; } + /** + * 获取请求的URL + * + * @return 请求的URL + */ + public String getRequestURI() { + return requestURI; + } + /** * 截取getRequestURI最后的一个/后面的部分 * @@ -525,33 +552,6 @@ public class HttpRequest extends Request { return val == null ? defvalue : Long.parseLong(val); } - /** - * 获取请求的URL - * - * @return 请求的URL - */ - public String getRequestURI() { - return requestURI; - } - - /** - * 获取请求内容的长度, 为-1表示内容长度不确定 - * - * @return 内容长度 - */ - public long getContentLength() { - return contentLength; - } - - /** - * 获取Content-Type的header值 - * - * @return contentType - */ - public String getContentType() { - return contentType; - } - //------------------------------------------------------------------------------ /** * 获取所有的header名 @@ -572,6 +572,17 @@ public class HttpRequest extends Request { return header.getValue(name); } + /** + * 获取指定的header值, 没有返回默认值 + * + * @param name header名 + * @param defaultValue 默认值 + * @return header值 + */ + public String getHeader(String name, String defaultValue) { + return header.getValue(name, defaultValue); + } + /** * 获取指定的header的json值 * @@ -665,17 +676,6 @@ public class HttpRequest extends Request { return header.getDoubleValue(name, defaultValue); } - /** - * 获取指定的header值, 没有返回默认值 - * - * @param name header名 - * @param defaultValue 默认值 - * @return header值 - */ - public String getHeader(String name, String defaultValue) { - return header.getValue(name, defaultValue); - } - //------------------------------------------------------------------------------ /** * 获取所有参数名 @@ -698,6 +698,18 @@ public class HttpRequest extends Request { return params.getValue(name); } + /** + * 获取指定的参数值, 没有返回默认值 + * + * @param name 参数名 + * @param defaultValue 默认值 + * @return 参数值 + */ + public String getParameter(String name, String defaultValue) { + parseBody(); + return params.getValue(name, defaultValue); + } + /** * 获取指定的参数json值 * @@ -797,15 +809,4 @@ public class HttpRequest extends Request { return params.getDoubleValue(name, defaultValue); } - /** - * 获取指定的参数值, 没有返回默认值 - * - * @param name 参数名 - * @param defaultValue 默认值 - * @return 参数值 - */ - public String getParameter(String name, String defaultValue) { - parseBody(); - return params.getValue(name, defaultValue); - } }