From 94b5a07fc92d3b3adef65672c0b472feab47bb71 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 9 May 2019 22:21:24 +0700 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D0=92=D0=B5=D1=80=D0=BD=D1=83=D0=BB?= =?UTF-8?q?=D0=B8=D1=81=D1=8C=20=D0=BD=D0=B0=D0=B7=D0=B0=D0=B4=20NettyIpFo?= =?UTF-8?q?rwardHandler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websocket/NettyIpForwardHandler.java | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/NettyIpForwardHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/NettyIpForwardHandler.java index 1adc5087..5013ea66 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/NettyIpForwardHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/NettyIpForwardHandler.java @@ -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 { +public class NettyIpForwardHandler extends MessageToMessageDecoder { 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 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 out) throws Exception { + if(msg instanceof ReferenceCounted) + { + ((ReferenceCounted) msg).retain(); + } if (context.ip != null) { out.add(msg); return;