I have some code in my haproxy.cfg file that rate limits requests and returns a 429 and it works beautifully. However, it returns a net::ERR_FAILED and skips past some error handling code I have on the front end. I’ve tried to update the haproxy.cfg to send a status with a content type of “text/plain” so I can handle the status code and let the user know what’s going on, but I’m still getting the net::ERR_FAILED. My update code is as follows:
frontend s4p
bind 192.168.250.146:80
stick-table type binary len 20 size 100k expire 10s store http_req_rate(10s)
# Track client by base32+src (Host header + URL path + src IP)
http-request track-sc0 base32+src
# Check map file to get rate limit for path
http-request set-var(req.rate_limit) path,map_beg(/etc/haproxy/rates.map,20)
# Client's request rate is tracked
http-request set-var(req.request_rate) base32+src,table_http_req_rate()
# Subtract the current request rate from the limit
# If less than zero, set rate_abuse to true
acl rate_abuse var(req.rate_limit),sub(req.request_rate) lt 0
# Deny if rate abuse
http-request return status 429 content-type "text/plain" if rate_abuse
http-request lua.cors "*" "*" "*"
http-response lua.cors
default_backend api_servers
Can someone help me figure out how to send a response back to the client with a net::ERR_FAILED?
Thanks!
2 posts - 2 participants