mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FIX] Вернулись назад NettyIpForwardHandler
This commit is contained in:
parent
236b433d5f
commit
94b5a07fc9
1 changed files with 6 additions and 23 deletions
|
@ -1,15 +1,15 @@
|
|||
package ru.gravit.launchserver.websocket;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageCodec;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
import io.netty.util.ReferenceCounted;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NettyIpForwardHandler extends MessageToMessageCodec<HttpRequest, HttpRequest> {
|
||||
public class NettyIpForwardHandler extends MessageToMessageDecoder<HttpRequest> {
|
||||
private NettyConnectContext context;
|
||||
|
||||
public NettyIpForwardHandler(NettyConnectContext context) {
|
||||
|
@ -17,29 +17,12 @@ public NettyIpForwardHandler(NettyConnectContext context) {
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, HttpRequest msg, List<Object> out) throws Exception {
|
||||
if (context.ip != null) {
|
||||
out.add(msg);
|
||||
return;
|
||||
}
|
||||
HttpHeaders headers = msg.headers();
|
||||
String realIP = null;
|
||||
if (headers.contains("X-Forwarded-For")) {
|
||||
realIP = headers.get("X-Forwarded-For");
|
||||
}
|
||||
if (headers.contains("X-Real-IP")) {
|
||||
realIP = headers.get("X-Real-IP");
|
||||
}
|
||||
if (realIP != null) {
|
||||
LogHelper.dev("Real IP address %s", realIP);
|
||||
context.ip = realIP;
|
||||
} else LogHelper.error("IpForwarding error. Headers not found");
|
||||
out.add(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, HttpRequest msg, List<Object> out) throws Exception {
|
||||
if(msg instanceof ReferenceCounted)
|
||||
{
|
||||
((ReferenceCounted) msg).retain();
|
||||
}
|
||||
if (context.ip != null) {
|
||||
out.add(msg);
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue