aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorW. Kosior <koszko@koszko.org>2024-07-23 23:17:29 +0200
committerW. Kosior <koszko@koszko.org>2024-07-23 23:17:29 +0200
commit6fc5e5fa1990d07de1b44fd4ac50cb388b3da480 (patch)
treefc391f76fb2eeaa5967a6c205ea8504f0b61af1f /src
parent72ce6cb22eee33b9ce418ee8adf3228237124710 (diff)
downloadcantius-6fc5e5fa1990d07de1b44fd4ac50cb388b3da480.tar.gz
cantius-6fc5e5fa1990d07de1b44fd4ac50cb388b3da480.zip
Add `parse-cookies' procedure.
Diffstat (limited to 'src')
-rw-r--r--src/guile/cantius.scm32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/guile/cantius.scm b/src/guile/cantius.scm
index 76cc5fa..8afb276 100644
--- a/src/guile/cantius.scm
+++ b/src/guile/cantius.scm
@@ -246,6 +246,38 @@
+;;;
+;;; Cookie parser
+;;;
+
+(define %cookie-regex
+ (make-regexp (string-append
+ "^\\s*"
+ "([^[:space:];=]([^;=]*[^[:space:];=])?)" ;; name
+ "\\s*=\\s*"
+ "(([^[:space:];]([^;]*[^[:space:];])?)?)" ;; value
+ "\\s*(;|$)")))
+
+(define-public (parse-cookies cookies)
+ (let loop ((idx 0)
+ (cookies-alist '()))
+ (match (regexp-exec %cookie-regex cookies idx)
+
+ (#f
+ (when (string-index cookies char-set:graphic idx)
+ (raise (s35:condition
+ (&bad-request)
+ (s35:&message
+ (message "Unparseable cookie")))))
+ (reverse cookies-alist))
+
+ ((and (= (cut match:substring <> 1) name)
+ (= (cut match:substring <> 3) value)
+ (= match:end idx*))
+ (loop idx* `((,name . ,value) . ,cookies-alist))))))
+
+
+
(define-public %current-path
(make-parameter #f))