Look into [std/asyncdispatch](https://nim-lang.org/docs/asyncdispatch.html) and [std/asynchttpserver](https://nim-lang.org/docs/asynchttpserver.html).
Notable, the proc [shouldAcceptRequest](https://nim-lang.org/docs/asynchttpserver.html#shouldAcceptRequest%2CAsyncHttpServer%2Cint) should be close to what you want