walkman69
Mar 25, 2024Altostratus
URL Distribution
I received a request as to the possibility to or distribute traffic for one url to multiple urls (round-robin, least connections, or even just randomly ) but never exceed 50 connections to each one. ...
- Mar 26, 2024
Not at all tested or optimized or secured against injection with the table commands, but to get the juices flowing I threw this together. Not 100% confident it'll work and I don't have time until end of the week to flesh out and test, but it is possible to achieve what you're after. That said, it'll be a support nightmare to grow with the needs of the business since it's not a well-defined problem or scale, so I would push back against this particular ask.
when HTTP_REQUEST priority 500 { if { [string tolower [HTTP::path]] == "/form"} { foreach form [list form1 form2 form3 form4 form5 form6] { if { [table lookup $form] < 50 } { table incr $form 1 HTTP::uri /$form set current_form $form break } } } } when HTTP_REQUEST priority 501 { if { [string tolower [HTTP::path]] == "/form" } { HTTP::respond 429 content "<html><body><p>All forms at max of 50 requests</p></body></html>" } } when HTTP_RESPONSE { table incr $current_form -1 }