Reputation: 35961
What is the proper way to deny/drop incoming connection to a Reactor TcpServer?
I currently have following:
TcpServer.create()
.doOnConnection {
if (notAllowed(it.address()) {
throw IllegalStateException("Connection from ${it.address()} denied")
}
}
.handle(...)
.bindNow()
It seems to be working and it successfully drops connections from remote addresses which are in my notAllowed
list. But each time it prints the stack trace to the console, and in general it doesn't look good.
What is the proper approach for denying some connections to TcpServer?
Upvotes: 0
Views: 194
Reputation: 2292
I would recommend you instead of throwing IllegalStateException
, just invoke Connection#dispose
TcpServer.create()
.doOnConnection {
if (notAllowed(it.address()) {
it.dispose()
}
}
.handle(...)
.bindNow()
Upvotes: 1