Description
An HTTP server is created using std.net.http.server.Server.new in combination with a closure that returns a uni type that implements std.net.http.server.Handle.
Currently this closure isn't passed any arguments, making it difficult to apply some form of rate limiting before accepting the first request.
For example, when throttling by IP some form of shared state is required. Using a process is possible but because of the above you have to wait for the first request to come in before you can determine the IP of the request. This means a client could still try to exhaust the server's resources by establishing many connections but never sending a request.
To prevent this from happening we need to:
- Pass the IP address to the handler, so it can be used before establishing the connection state
- A way to signal back to the
Server to abort setting up the connection, ideally without being forced to always return a Option[uni H: Handle]
Using this approach you could for example stick the IP into a Map along with the connection count, then reject the connection if the number is too large.
There are however some additional challenges with this:
- Whatever dataset you store the IP in should have an upper bound, so you don't end up with 200 000 entries consuming more memory than the connections would otherwise consume
- It will likely make the API more clunky, which I want to avoid
- It doesn't account for residential proxies where some scraper uses 200 different IPs each establishing one connection, instead of one IP establishing 200 connections
Related work
No response
Description
An HTTP server is created using
std.net.http.server.Server.newin combination with a closure that returns aunitype that implementsstd.net.http.server.Handle.Currently this closure isn't passed any arguments, making it difficult to apply some form of rate limiting before accepting the first request.
For example, when throttling by IP some form of shared state is required. Using a process is possible but because of the above you have to wait for the first request to come in before you can determine the IP of the request. This means a client could still try to exhaust the server's resources by establishing many connections but never sending a request.
To prevent this from happening we need to:
Serverto abort setting up the connection, ideally without being forced to always return aOption[uni H: Handle]Using this approach you could for example stick the IP into a
Mapalong with the connection count, then reject the connection if the number is too large.There are however some additional challenges with this:
Related work
No response