mirror of
https://github.com/penpot/penpot.git
synced 2025-05-05 02:45:54 +02:00
🔥 Remove ratelimit (delegate this task to nginx).
This commit is contained in:
parent
1a82fc28d3
commit
c0b3618331
3 changed files with 1 additions and 61 deletions
|
@ -29,9 +29,6 @@
|
||||||
{:local/root "vendor/sodi"
|
{:local/root "vendor/sodi"
|
||||||
:deps/manifest :pom}
|
:deps/manifest :pom}
|
||||||
|
|
||||||
io.github.resilience4j/resilience4j-core {:mvn/version "1.2.0"}
|
|
||||||
io.github.resilience4j/resilience4j-ratelimiter {:mvn/version "1.2.0"}
|
|
||||||
|
|
||||||
lambdaisland/uri {:mvn/version "1.1.0"}
|
lambdaisland/uri {:mvn/version "1.1.0"}
|
||||||
|
|
||||||
danlentz/clj-uuid {:mvn/version "0.1.9"}
|
danlentz/clj-uuid {:mvn/version "0.1.9"}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
[uxbox.http.session :as session]
|
[uxbox.http.session :as session]
|
||||||
[uxbox.http.handlers :as handlers]
|
[uxbox.http.handlers :as handlers]
|
||||||
[uxbox.http.debug :as debug]
|
[uxbox.http.debug :as debug]
|
||||||
[uxbox.http.ratelimit :as rl]
|
|
||||||
[uxbox.http.ws :as ws]
|
[uxbox.http.ws :as ws]
|
||||||
[vertx.core :as vc]
|
[vertx.core :as vc]
|
||||||
[vertx.http :as vh]
|
[vertx.http :as vh]
|
||||||
|
@ -38,12 +37,6 @@
|
||||||
interceptors/format-response-body
|
interceptors/format-response-body
|
||||||
(vxi/errors errors/handle)]
|
(vxi/errors errors/handle)]
|
||||||
|
|
||||||
login-handler (rl/ratelimit handlers/login-handler
|
|
||||||
{:limit 10
|
|
||||||
:period 1000
|
|
||||||
:timeout 200
|
|
||||||
:name "login-handler"})
|
|
||||||
|
|
||||||
routes [["/sub/:file-id" {:interceptors [(vxi/cookies)
|
routes [["/sub/:file-id" {:interceptors [(vxi/cookies)
|
||||||
(vxi/cors cors-opts)
|
(vxi/cors cors-opts)
|
||||||
interceptors/format-response-body
|
interceptors/format-response-body
|
||||||
|
@ -52,7 +45,7 @@
|
||||||
|
|
||||||
["/api" {:interceptors interceptors}
|
["/api" {:interceptors interceptors}
|
||||||
["/echo" {:all handlers/echo-handler}]
|
["/echo" {:all handlers/echo-handler}]
|
||||||
["/login" {:post login-handler}]
|
["/login" {:post handlers/login-handler}]
|
||||||
["/logout" {:post handlers/logout-handler}]
|
["/logout" {:post handlers/logout-handler}]
|
||||||
["/debug"
|
["/debug"
|
||||||
["/emails" {:get debug/emails-list}]
|
["/emails" {:get debug/emails-list}]
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
||||||
;; defined by the Mozilla Public License, v. 2.0.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016-2019 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.http.ratelimit
|
|
||||||
"Rate limit"
|
|
||||||
(:require
|
|
||||||
[clojure.spec.alpha :as s]
|
|
||||||
[uxbox.common.exceptions :as ex]
|
|
||||||
[uxbox.core :refer [system]]
|
|
||||||
[vertx.core :as vc]
|
|
||||||
[promesa.core :as p]
|
|
||||||
[promesa.exec :as pe])
|
|
||||||
(:import
|
|
||||||
io.github.resilience4j.ratelimiter.RateLimiter
|
|
||||||
io.github.resilience4j.ratelimiter.RateLimiterConfig
|
|
||||||
io.github.resilience4j.ratelimiter.RateLimiterRegistry
|
|
||||||
java.util.concurrent.CompletableFuture
|
|
||||||
java.util.function.Supplier
|
|
||||||
java.time.Duration))
|
|
||||||
|
|
||||||
;; --- Rate Limiter
|
|
||||||
|
|
||||||
(def ^:private registry (RateLimiterRegistry/ofDefaults))
|
|
||||||
|
|
||||||
(defn- opts->rate-limiter-config
|
|
||||||
[{:keys [limit period timeout] :as opts}]
|
|
||||||
(let [custom (RateLimiterConfig/custom)]
|
|
||||||
(.limitRefreshPeriod custom (Duration/ofMillis period))
|
|
||||||
(.limitForPeriod custom limit)
|
|
||||||
(.timeoutDuration custom (Duration/ofMillis timeout))
|
|
||||||
(.build custom)))
|
|
||||||
|
|
||||||
(defn ratelimit
|
|
||||||
[f {:keys [name] :as opts}]
|
|
||||||
(let [config (opts->rate-limiter-config opts)
|
|
||||||
rl (.rateLimiter registry name config)]
|
|
||||||
(fn [& args]
|
|
||||||
(let [ctx (vc/get-or-create-context system)]
|
|
||||||
(-> (pe/run! #(when-not (.acquirePermission rl 1)
|
|
||||||
(ex/raise :type :ratelimit
|
|
||||||
:code :timeout
|
|
||||||
:context {:name name})))
|
|
||||||
(vc/handle-on-context)
|
|
||||||
(p/bind (fn [_] (p/do! (apply f args)))))))))
|
|
Loading…
Add table
Reference in a new issue