Previous implementation was quite naive and assumed a lot of non-guaranteed premises. Checking if our session is valid before doing each request is very stupid, but it was needed for multi-user sessions. Next, even if we checked that our session is valid (or revalidated it if needed), we then assumed it's valid for at least X seconds, which is once again entirely false. Moreover, on top of those two issues, refreshing our session could do absolutely nothing as there is no guarantee that once-refreshes session stays like that even for our very next request.
Get rid of all of this shit and rewrite it with proper mechanism. We're making a request, if that request results in redirection to session refresh, refresh session, then repeat the same request again. Add failsafes for infinite loops, make it enough thread-safe and optimized for concurrent usage.
This commit won't only improve previously half-valid implementation, but will also greatly optimize number of requests being sent, as we won't need to check our session before each request. The entire thing should work like that since beginning.
Good thing that somebody actually reads my commits, you can pat yourself on the back for being awesome 👍
Just in case you have no clue what the code actually does - no, it doesn't have any bitcoin miner inside. You owe me 1$ donation for explanation 😆
And if you know what it does - don't use it just yet, I'll document it once I deem it stable.
This makes it possible to not only listen on multiple different host/port combinations, but also different protocols or base URLs (even though this will probably break things up, need to do more tests)