Compare commits

..

2 Commits

Author SHA1 Message Date
woggioni 8825836832 improved logging
CI / build (push) Successful in 2m45s
2025-12-30 21:53:23 +08:00
woggioni 5854a632f8 Added server support for proxy protocol 2025-12-29 22:21:34 +08:00
2 changed files with 25 additions and 1 deletions
@@ -0,0 +1,17 @@
package net.woggioni.rbcs.common
import java.net.InetAddress
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class CidrTest {
class CidrTest {
@Test
fun test() {
val cidr = Cidr.from("2a02:4780:12:368b::1/128")
Assertions.assertTrue {
cidr.contains(InetAddress.ofLiteral("2a02:4780:12:368b::1"))
}
}
}
}
@@ -24,7 +24,14 @@ class ProxyProtocolHandler(private val trustedProxyIPs : List<Cidr>) : SimpleCha
val sourceAddress = ctx.channel().remoteAddress() val sourceAddress = ctx.channel().remoteAddress()
if (sourceAddress is InetSocketAddress && if (sourceAddress is InetSocketAddress &&
trustedProxyIPs.isEmpty() || trustedProxyIPs.isEmpty() ||
trustedProxyIPs.any { it.contains((sourceAddress as InetSocketAddress).address) }) { trustedProxyIPs.any { it.contains((sourceAddress as InetSocketAddress).address) }.also {
if(log.isTraceEnabled) {
log.trace {
"Received proxied request from $sourceAddress which is not a trusted proxy address, " +
"the proxy server address will be used instead"
}
}
}) {
val proxiedClientAddress = InetSocketAddress( val proxiedClientAddress = InetSocketAddress(
InetAddress.ofLiteral(msg.sourceAddress()), InetAddress.ofLiteral(msg.sourceAddress()),
msg.sourcePort() msg.sourcePort()