mholt / caddy-ratelimit

HTTP rate limiting module for Caddy 2
Apache License 2.0
255 stars 17 forks source link

Response message is missing #52

Closed sowinski closed 5 months ago

sowinski commented 5 months ago

Hi,

I successfully tested your rate limiter. If I hit the limit, I get a 429 message. But it is messing any content.

I would like to see something like "Too Many Requests. Please try again later." in my browser.

Not sure if is possible otherwise it would be nice to add this feature in later releases. From a user perspective this is not nice

Thank you and great work!

francislavoie commented 5 months ago

You can use https://caddyserver.com/docs/caddyfile/directives/handle_errors to write a custom response for specific errors

mholt commented 5 months ago

Yep, like Francis said, Caddy HTTP handlers will return a Go error value that bubbles up to the HTTP server, which then invokes error routes to handle the error if they are configured. So use handle_errors to handle 429s.

sowinski commented 5 months ago

Thank you. I ended up with this

      caddy.handle_errors: 429
      caddy.handle_errors.respond: "\"Too Many Requests. Please try again later.\""