This commit is contained in:
wentch
2016-01-19 10:38:18 +08:00
parent 0d7576ecb1
commit 72fda8c336

View File

@@ -224,6 +224,15 @@ public class HttpRequest extends Request<HttpContext> {
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<HttpContext> {
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<HttpContext> {
+ ", host:" + this.host + ", params:" + this.params + ", header:" + this.header + "}";
}
/**
* 获取文件上传信息列表
*
* @return 文件上传对象集合
* @throws IOException IO异常
*/
public final Iterable<MultiPart> multiParts() throws IOException {
return getMultiContext().parts();
}
/**
* 获取文件上传对象
*
@@ -303,6 +293,16 @@ public class HttpRequest extends Request<HttpContext> {
}, null);
}
/**
* 获取文件上传信息列表
*
* @return 文件上传对象集合
* @throws IOException IO异常
*/
public final Iterable<MultiPart> multiParts() throws IOException {
return getMultiContext().parts();
}
@Override
protected void recycle() {
this.cookiestr = null;
@@ -407,12 +407,12 @@ public class HttpRequest extends Request<HttpContext> {
}
/**
* 获取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<HttpContext> {
}
/**
* 获取协议名 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<HttpContext> {
return host;
}
/**
* 获取请求的URL
*
* @return 请求的URL
*/
public String getRequestURI() {
return requestURI;
}
/**
* 截取getRequestURI最后的一个/后面的部分
*
@@ -525,33 +552,6 @@ public class HttpRequest extends Request<HttpContext> {
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<HttpContext> {
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<HttpContext> {
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<HttpContext> {
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<HttpContext> {
return params.getDoubleValue(name, defaultValue);
}
/**
* 获取指定的参数值, 没有返回默认值
*
* @param name 参数名
* @param defaultValue 默认值
* @return 参数值
*/
public String getParameter(String name, String defaultValue) {
parseBody();
return params.getValue(name, defaultValue);
}
}