Is there some obvious way to implement rate-limiting for a Pedestal web service?
with a proxy like Nginx or Kong?
@lkottmann no proxy at the moment. I don't expect I'll need one, though if that's the preferred way to get rate limiting I guess I will?
there are ring middlewares if you want a clojure-only solution
I guess an alternative to using ring-middleware in a Pedestal app is to use one these Jetty filters: • https://www.eclipse.org/jetty/documentation/current/dos-filter.html • https://www.eclipse.org/jetty/documentation/current/qos-filter.html I would want to do it from Clojure, though, not through XML. Anyone have any experience setting up Jetty filters in Pedestal?
Perhaps using the `:context-configurator` key in the Jetty configuration and code similar to this? https://www.programcreek.com/java-api-examples/?class=org.eclipse.jetty.servlet.ServletContextHandler&method=addFilter I have no idea how to use `:context-configurator` though. The Pedestal documentation simply says: > “A function called with the `org.eclipse.jetty.servlet.ServletContextHandler` instance. Use when advanced customization is required.”
Scratch that, I got confused. `:context-configurator` is a just function you define taking one arg (the current org.eclipse.jetty.servlet.ServletContextHandler) and obviously methods can then be called on it in that context.
Here how I use context-configurator
(defn context-configurator
[^ServletContextHandler context]
(let [gzip-handler (GzipHandler.)]
(.setExcludedAgentPatterns gzip-handler (make-array String 0))
(.setGzipHandler context gzip-handler))
context)
... ::http/container-options {:h2c? true
:context-configurator context-configurator}
Thanks. Pretty simple stuff.