增加HttpRequest.remoteAddrHeaders属性
This commit is contained in:
@@ -3,18 +3,17 @@
|
||||
*/
|
||||
package org.redkale.mq.spi;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Repeatable;
|
||||
import java.lang.annotation.Retention;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.annotation.Target;
|
||||
import org.redkale.mq.MessageConsumer;
|
||||
|
||||
/**
|
||||
* 只标准在类上面,因动态方法不作变动,只增加内部类
|
||||
* 用于识别方法是否已经动态处理过
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
*/
|
||||
package org.redkale.net.http;
|
||||
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.SecureRandom;
|
||||
@@ -14,6 +12,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.redkale.annotation.ConstructorParameters;
|
||||
import org.redkale.asm.*;
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.net.Context.ContextConfig;
|
||||
import org.redkale.util.*;
|
||||
@@ -33,6 +32,9 @@ public class HttpContext extends Context {
|
||||
|
||||
protected final String remoteAddrHeader;
|
||||
|
||||
// 用逗号隔开的多个header
|
||||
protected final String[] remoteAddrHeaders;
|
||||
|
||||
protected final String localHeader;
|
||||
|
||||
protected final String localParameter;
|
||||
@@ -50,6 +52,7 @@ public class HttpContext extends Context {
|
||||
public HttpContext(HttpContextConfig config) {
|
||||
super(config);
|
||||
this.remoteAddrHeader = config.remoteAddrHeader;
|
||||
this.remoteAddrHeaders = config.remoteAddrHeaders;
|
||||
this.localHeader = config.localHeader;
|
||||
this.localParameter = config.localParameter;
|
||||
this.rpcAuthenticator = config.rpcAuthenticator;
|
||||
@@ -232,6 +235,9 @@ public class HttpContext extends Context {
|
||||
|
||||
public String remoteAddrHeader;
|
||||
|
||||
// 用逗号隔开的多个header
|
||||
public String[] remoteAddrHeaders;
|
||||
|
||||
public String localHeader;
|
||||
|
||||
public String localParameter;
|
||||
|
||||
@@ -167,6 +167,9 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
|
||||
private final String remoteAddrHeader;
|
||||
|
||||
// 用逗号隔开的多个header
|
||||
private final String[] remoteAddrHeaders;
|
||||
|
||||
private final String localHeader;
|
||||
|
||||
private final String localParameter;
|
||||
@@ -183,6 +186,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
super(context);
|
||||
this.array = array;
|
||||
this.remoteAddrHeader = context.remoteAddrHeader;
|
||||
this.remoteAddrHeaders = context.remoteAddrHeaders;
|
||||
this.localHeader = context.localHeader;
|
||||
this.localParameter = context.localParameter;
|
||||
this.rpcAuthenticator = context.rpcAuthenticator;
|
||||
@@ -193,6 +197,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
super(context);
|
||||
this.array = new ByteArray();
|
||||
this.remoteAddrHeader = null;
|
||||
this.remoteAddrHeaders = null;
|
||||
this.localHeader = null;
|
||||
this.localParameter = null;
|
||||
this.rpcAuthenticator = null;
|
||||
@@ -1470,17 +1475,26 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
return this.remoteAddr;
|
||||
}
|
||||
parseHeader();
|
||||
String ipValue = null;
|
||||
if (remoteAddrHeader != null) {
|
||||
String val = getHeader(remoteAddrHeader);
|
||||
if (val != null) {
|
||||
int pos = val.indexOf(',');
|
||||
if (pos > 6) {
|
||||
val = val.substring(0, pos);
|
||||
ipValue = getHeader(remoteAddrHeader);
|
||||
} else if (remoteAddrHeaders != null) {
|
||||
for (String h : remoteAddrHeaders) {
|
||||
ipValue = getHeader(h);
|
||||
if (ipValue != null && !ipValue.isBlank()) {
|
||||
break;
|
||||
}
|
||||
this.remoteAddr = val;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
if (ipValue != null) {
|
||||
int pos = ipValue.indexOf(',');
|
||||
if (pos > 3) {
|
||||
ipValue = ipValue.substring(0, pos);
|
||||
}
|
||||
this.remoteAddr = ipValue;
|
||||
return ipValue;
|
||||
}
|
||||
|
||||
SocketAddress addr = getRemoteAddress();
|
||||
if (addr == null) {
|
||||
return "";
|
||||
|
||||
@@ -516,8 +516,8 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
||||
Supplier<byte[]> dateSupplier = null;
|
||||
if (datePeriod == 0) {
|
||||
final ZoneId gmtZone = ZoneId.of("GMT");
|
||||
dateSupplier = () ->
|
||||
("Date: " + RFC_1123_DATE_TIME.format(java.time.ZonedDateTime.now(gmtZone)) + "\r\n").getBytes();
|
||||
dateSupplier =
|
||||
("Date: " + RFC_1123_DATE_TIME.format(java.time.ZonedDateTime.now(gmtZone)) + "\r\n")::getBytes;
|
||||
} else if (datePeriod > 0) {
|
||||
if (this.dateScheduler == null) {
|
||||
this.dateScheduler = new ScheduledThreadPoolExecutor(1, (Runnable r) -> {
|
||||
@@ -545,7 +545,7 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
||||
1000 - System.currentTimeMillis() % 1000,
|
||||
datePeriod,
|
||||
TimeUnit.MILLISECONDS);
|
||||
dateSupplier = () -> dateRef.get();
|
||||
dateSupplier = dateRef::get;
|
||||
}
|
||||
}
|
||||
HttpRender httpRender = null;
|
||||
@@ -585,7 +585,13 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
||||
|
||||
final HttpContextConfig contextConfig = new HttpContextConfig();
|
||||
initContextConfig(contextConfig);
|
||||
contextConfig.remoteAddrHeader = addrHeader;
|
||||
if (addrHeader != null && addrHeader.indexOf(',') > 0) {
|
||||
contextConfig.remoteAddrHeader = null;
|
||||
contextConfig.remoteAddrHeaders = addrHeader.replaceAll("\\s+", "").split(",");
|
||||
} else {
|
||||
contextConfig.remoteAddrHeader = addrHeader;
|
||||
contextConfig.remoteAddrHeaders = null;
|
||||
}
|
||||
contextConfig.localHeader = localHeader;
|
||||
contextConfig.localParameter = localParameter;
|
||||
contextConfig.rpcAuthenticatorConfig = rpcAuthenticatorConfig;
|
||||
|
||||
Reference in New Issue
Block a user