This commit is contained in:
Redkale
2020-05-30 11:55:34 +08:00
parent 450506ca96
commit 411f5e1951

View File

@@ -14,6 +14,7 @@ import java.nio.channels.Channels;
import java.nio.charset.*; import java.nio.charset.*;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import org.redkale.convert.ConvertDisabled;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
import org.redkale.net.*; import org.redkale.net.*;
import org.redkale.util.AnyValue.DefaultAnyValue; import org.redkale.util.AnyValue.DefaultAnyValue;
@@ -279,7 +280,7 @@ public class HttpRequest extends Request<HttpContext> {
* 数据类型通常是int、long、String * 数据类型通常是int、long、String
* *
* @param <T> 泛型 * @param <T> 泛型
* @param user 用户信息 * @param userid 用户ID
* *
* @return HttpRequest * @return HttpRequest
*/ */
@@ -338,6 +339,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return 模块ID * @return 模块ID
*/ */
@ConvertDisabled
public int getModuleid() { public int getModuleid() {
return this.moduleid; return this.moduleid;
} }
@@ -347,6 +349,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return 模块ID * @return 模块ID
*/ */
@ConvertDisabled
public int getActionid() { public int getActionid() {
return this.actionid; return this.actionid;
} }
@@ -356,6 +359,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return Annotation[] * @return Annotation[]
*/ */
@ConvertDisabled
public Annotation[] getAnnotations() { public Annotation[] getAnnotations() {
if (this.annotations == null) return new Annotation[0]; if (this.annotations == null) return new Annotation[0];
Annotation[] newanns = new Annotation[this.annotations.length]; Annotation[] newanns = new Annotation[this.annotations.length];
@@ -405,6 +409,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return 地址 * @return 地址
*/ */
@ConvertDisabled
public SocketAddress getRemoteAddress() { public SocketAddress getRemoteAddress() {
return this.channel == null || !this.channel.isOpen() ? null : this.channel.getRemoteAddress(); return this.channel == null || !this.channel.isOpen() ? null : this.channel.getRemoteAddress();
} }
@@ -442,6 +447,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return 内容 * @return 内容
*/ */
@ConvertDisabled
public String getBodyUTF8() { public String getBodyUTF8() {
return array.toString(StandardCharsets.UTF_8); return array.toString(StandardCharsets.UTF_8);
} }
@@ -481,7 +487,7 @@ public class HttpRequest extends Request<HttpContext> {
* @return 内容 * @return 内容
*/ */
public byte[] getBody() { public byte[] getBody() {
return array.getBytes(); return array.size() == 0 ? null : array.getBytes();
} }
/** /**
@@ -489,6 +495,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return body对象 * @return body对象
*/ */
@ConvertDisabled
protected ByteArray getDirectBody() { protected ByteArray getDirectBody() {
return array; return array;
} }
@@ -508,6 +515,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return 文件上传对象 * @return 文件上传对象
*/ */
@ConvertDisabled
public final MultiContext getMultiContext() { public final MultiContext getMultiContext() {
return new MultiContext(context.getCharset(), this.getContentType(), this.params, return new MultiContext(context.getCharset(), this.getContentType(), this.params,
new BufferedInputStream(Channels.newInputStream(this.channel), Math.max(array.size(), 8192)) { new BufferedInputStream(Channels.newInputStream(this.channel), Math.max(array.size(), 8192)) {
@@ -525,6 +533,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @throws IOException IO异常 * @throws IOException IO异常
*/ */
@ConvertDisabled
public final Iterable<MultiPart> multiParts() throws IOException { public final Iterable<MultiPart> multiParts() throws IOException {
return getMultiContext().parts(); return getMultiContext().parts();
} }
@@ -565,6 +574,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return sessionid * @return sessionid
*/ */
@ConvertDisabled
public String getSessionid(boolean create) { public String getSessionid(boolean create) {
String sessionid = getCookie(SESSIONID_NAME, null); String sessionid = getCookie(SESSIONID_NAME, null);
if (create && (sessionid == null || sessionid.isEmpty())) { if (create && (sessionid == null || sessionid.isEmpty())) {
@@ -610,7 +620,7 @@ public class HttpRequest extends Request<HttpContext> {
*/ */
public HttpCookie[] getCookies() { public HttpCookie[] getCookies() {
if (this.cookies == null) this.cookies = parseCookies(this.cookie); if (this.cookies == null) this.cookies = parseCookies(this.cookie);
return this.cookies; return this.cookies.length == 0 ? null : this.cookies;
} }
/** /**
@@ -633,7 +643,9 @@ public class HttpRequest extends Request<HttpContext> {
* @return cookie值 * @return cookie值
*/ */
public String getCookie(String name, String dfvalue) { public String getCookie(String name, String dfvalue) {
for (HttpCookie c : getCookies()) { HttpCookie[] cs = getCookies();
if (cs == null) return dfvalue;
for (HttpCookie c : cs) {
if (name.equals(c.getName())) return c.getValue(); if (name.equals(c.getName())) return c.getValue();
} }
return dfvalue; return dfvalue;
@@ -732,6 +744,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return String * @return String
*/ */
@ConvertDisabled
public String getRequstURILastPath() { public String getRequstURILastPath() {
if (requestURI == null) return ""; if (requestURI == null) return "";
return requestURI.substring(requestURI.lastIndexOf('/') + 1); return requestURI.substring(requestURI.lastIndexOf('/') + 1);
@@ -1092,6 +1105,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return Map * @return Map
*/ */
@ConvertDisabled
public Map<String, String> getHeadersToMap(Map<String, String> map) { public Map<String, String> getHeadersToMap(Map<String, String> map) {
if (map == null) map = new LinkedHashMap<>(); if (map == null) map = new LinkedHashMap<>();
final Map<String, String> map0 = map; final Map<String, String> map0 = map;
@@ -1104,6 +1118,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return header名数组 * @return header名数组
*/ */
@ConvertDisabled
public String[] getHeaderNames() { public String[] getHeaderNames() {
return header.getNames(); return header.getNames();
} }
@@ -1314,6 +1329,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return Map * @return Map
*/ */
@ConvertDisabled
public Map<String, String> getParametersToMap(Map<String, String> map) { public Map<String, String> getParametersToMap(Map<String, String> map) {
if (map == null) map = new LinkedHashMap<>(); if (map == null) map = new LinkedHashMap<>();
final Map<String, String> map0 = map; final Map<String, String> map0 = map;
@@ -1328,6 +1344,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return String * @return String
*/ */
@ConvertDisabled
public String getParametersToString() { public String getParametersToString() {
return getParametersToString(null); return getParametersToString(null);
} }
@@ -1353,6 +1370,7 @@ public class HttpRequest extends Request<HttpContext> {
* *
* @return 参数名数组 * @return 参数名数组
*/ */
@ConvertDisabled
public String[] getParameterNames() { public String[] getParameterNames() {
parseBody(); parseBody();
return params.getNames(); return params.getNames();