Rate_limit plugin

Hi,

I’ve seen some discussion about this, for example this:

and especially this:

I’ve taken over the work by sk0g and I’ve published this:

It has to support also Header like the limit_by_header directive of caddy1 plugin.

What do you think? Thanks

2 Likes

Cool! Thanks for publishing that.

I’d recommend making this a caddy.Duration type, if possible, to be consistent with other timeframes in Caddy configuration:

Consider expanding on the godoc as that is what users will see when they look for documentation.

(Other than this, I haven’t given it any code review. Just a quick glance.)

Great start!

Thanks for the feedback Matt.
Do you have any code sample about using caddy.Duration in a plugin? It would help me a lot. Thanks

You just need to use the caddy.Duration type instead of int64:

And parse it like this for Caddyfile support:

https://github.com/francislavoie/caddy/blob/caddyfile-server-options/caddyconfig/httpcaddyfile/serveroptions.go#L90-L97

Also, I strongly suggest to use ,omitempty in your json tags, because otherwise, running caddy adapt will output "window_length": 0 even if the user never explicitly configured that value.

1 Like

Thanks for the help.

I’ve updated the plugin with your suggestion: Use duration for WindowLength · hundertzehn/caddy-ratelimit@45bd8b1 · GitHub

Best regards

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.