pedestal

simongray 2020-11-20T09:01:48.167500Z

Is there some obvious way to implement rate-limiting for a Pedestal web service?

Louis Kottmann 2020-11-20T10:12:19.167800Z

with a proxy like Nginx or Kong?

simongray 2020-11-20T10:18:44.169800Z

@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?

Louis Kottmann 2020-11-20T10:22:31.171200Z

there are ring middlewares if you want a clojure-only solution

simongray 2020-11-20T12:16:17.173Z

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.htmlhttps://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?

simongray 2020-11-20T12:19:41.173500Z

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.”

simongray 2020-11-20T12:28:03.176100Z

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.

souenzzo 2020-11-20T12:47:58.176200Z

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}

👍 1
simongray 2020-11-20T12:55:15.176500Z

Thanks. Pretty simple stuff.