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