-
Notifications
You must be signed in to change notification settings - Fork 2
/
middleware.lisp
36 lines (32 loc) · 1010 Bytes
/
middleware.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(in-package :germinal)
(defun basic-logging (handler)
"Middleware that logs requests to *standard-output*."
(lambda (request)
(let ((response (funcall handler request)))
(format
*standard-output*
"[~A] ~A \"~A\" ~A ~A ~%"
(local-time:now)
(usocket:host-to-hostname (request-client-address request))
(request-pathinfo request)
(response-status response)
(response-meta response))
response)))
(defun validate-server-name (handler)
"Middleware that ensures the requested host matches *germinal-server-name*."
(lambda (request)
(let* ((url (request-url request))
(host (uri-host url)))
(if (not (scan *germinal-server-name* host))
(make-response 51 "Not Found")
(funcall handler request)))))
(defun gemini-app (request)
(serve-route request))
(defun middleware-chain (middlewares)
(reduce
#'funcall
(remove-if
#'null
middlewares)
:initial-value #'gemini-app
:from-end t))