summaryrefslogtreecommitdiff
path: root/haunt/api.scm
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2022-11-20 20:50:36 -0500
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2022-11-20 20:50:36 -0500
commit2a7b250df5fa9611c2270c5837fab9fab750563c (patch)
tree86a6f95d673d3737708bf45b791d93d38286197e /haunt/api.scm
parent0d7dbb395c3bc166f0a6db6d3167531facef62fc (diff)
[dynamic] Initial rate limiter
Diffstat (limited to 'haunt/api.scm')
-rw-r--r--haunt/api.scm24
1 files changed, 13 insertions, 11 deletions
diff --git a/haunt/api.scm b/haunt/api.scm
index 1d275f8..b1db096 100644
--- a/haunt/api.scm
+++ b/haunt/api.scm
@@ -21,6 +21,7 @@
(jakob dynamic capabilities gallery)
(jakob dynamic capabilities rsvp)
(jakob dynamic logging)
+ (jakob dynamic rate-limiter)
(srfi srfi-1)
(web request)
(web response)
@@ -39,17 +40,18 @@
(originating-ip (assoc-ref (request-headers request) 'X-Forwarded-For))
(args (uri-query (request-uri request))))
(log-append! 'info (format #f "~a ~a (~a) (~a)" method endpoint args originating-ip)))
- ((match (cons (request-method request) endpoint)
- (('GET "comment-form" _) get-comment-form)
- ('(GET "challenge" "proof-of-work") make-pow-challenge!)
- ('(GET "challenge" "captcha") make-captcha-challenge!)
- ;; ('(GET "comments") get-comments)
- (('POST "comment") put-comment)
- (('GET "gallery") get-gallery)
- (('GET "gallery" "image") get-image)
- (('GET "rsvp" "event-info") get-event-info)
- (('POST "rsvp") post-event-rsvp)
- (_ (lambda (. args) (not-found request))))
+ ((rate-limit-wrap
+ (match (cons (request-method request) endpoint)
+ (('GET "comment-form" _) get-comment-form)
+ ('(GET "challenge" "proof-of-work") make-pow-challenge!)
+ ('(GET "challenge" "captcha") make-captcha-challenge!)
+ ;; ('(GET "comments") get-comments)
+ (('POST "comment") put-comment)
+ (('GET "gallery") get-gallery)
+ (('GET "gallery" "image") get-image)
+ (('GET "rsvp" "event-info") get-event-info)
+ (('POST "rsvp") post-event-rsvp)
+ (_ (lambda (. args) (not-found request)))))
request body))
(define (main-request-handler request body)