mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FIX] Исправление записи сообщения NettyIpForwardHandler 3
This commit is contained in:
parent
66f0a8b9d1
commit
c8e9918cd9
1 changed files with 19 additions and 29 deletions
|
@ -1,14 +1,14 @@
|
||||||
package ru.gravit.launchserver.websocket;
|
package ru.gravit.launchserver.websocket;
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandler;
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
||||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
|
||||||
import io.netty.handler.codec.http.HttpHeaders;
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
import io.netty.handler.codec.http.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
public class NettyIpForwardHandler extends ChannelInboundHandlerAdapter {
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NettyIpForwardHandler extends MessageToMessageDecoder<HttpRequest> {
|
||||||
private NettyConnectContext context;
|
private NettyConnectContext context;
|
||||||
|
|
||||||
public NettyIpForwardHandler(NettyConnectContext context) {
|
public NettyIpForwardHandler(NettyConnectContext context) {
|
||||||
|
@ -17,33 +17,23 @@ public NettyIpForwardHandler(NettyConnectContext context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
protected void decode(ChannelHandlerContext ctx, HttpRequest msg, List<Object> out) throws Exception {
|
||||||
//super.channelRead(ctx, msg);
|
if (context.ip != null) {
|
||||||
if(context.ip != null)
|
out.add(msg);
|
||||||
{
|
|
||||||
ctx.writeAndFlush(msg);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(msg instanceof HttpRequest)
|
HttpHeaders headers = msg.headers();
|
||||||
{
|
String realIP = null;
|
||||||
HttpRequest http = (HttpRequest) msg;
|
if (headers.contains("X-Forwarded-For")) {
|
||||||
HttpHeaders headers = http.headers();
|
realIP = headers.get("X-Forwarded-For");
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
else LogHelper.error("IpForwarding error. Real message class %s", msg.getClass().getName());
|
if (headers.contains("X-Real-IP")) {
|
||||||
ctx.writeAndFlush(msg);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue