针对HTTP代理附加对象的优化
This commit is contained in:
@@ -4,6 +4,7 @@ import io.netty.channel.Channel;
|
||||
import io.netty.util.AttributeKey;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -33,6 +34,8 @@ public interface Constants {
|
||||
|
||||
AttributeKey<Boolean> FLOW_LIMITER_FLAG = AttributeKey.newInstance("flowLimiterFlag");
|
||||
|
||||
AttributeKey<ProxyAttachment> PROXY_CONNECT_ATTACHMENT = AttributeKey.newInstance("proxyConnectAttachment");;
|
||||
|
||||
|
||||
int HEADER_SIZE = 4;
|
||||
int TYPE_SIZE = 1;
|
||||
@@ -51,4 +54,20 @@ public interface Constants {
|
||||
String ERROR = "ERROR";
|
||||
String PORT_MAPPING_SYNC = "PORT_MAPPING_SYNC";
|
||||
}
|
||||
|
||||
class ProxyAttachment {
|
||||
private byte[] bytes;
|
||||
private BiConsumer<Channel, byte[]> executor;
|
||||
|
||||
public ProxyAttachment(byte[] bytes, BiConsumer<Channel, byte[]> executor) {
|
||||
this.bytes = bytes;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public void execute(Channel channel) {
|
||||
if (null != executor && null != channel && channel.isActive()) {
|
||||
this.executor.accept(channel, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user