aboutsummaryrefslogtreecommitdiff
path: root/module/web/query.scm
diff options
context:
space:
mode:
Diffstat (limited to 'module/web/query.scm')
-rw-r--r--module/web/query.scm16
1 files changed, 16 insertions, 0 deletions
diff --git a/module/web/query.scm b/module/web/query.scm
new file mode 100644
index 00000000..cb96824d
--- /dev/null
+++ b/module/web/query.scm
@@ -0,0 +1,16 @@
+(define-module (web query)
+ :use-module (util)
+ :use-module (srfi srfi-1)
+ :use-module (web uri))
+
+(define*-public (parse-query query-string optional: (encoding "UTF-8"))
+ (unless (or (not query-string) (string-null? query-string))
+ (fold (lambda (str list)
+ ;; only split on the first equal.
+ ;; Does HTTP allow multiple equal signs in a data field?
+ ;; NOTE that this fails if str lacks an equal sign.
+ (define idx (string-index str #\=))
+ (define key (uri-decode (substring str 0 idx) encoding: encoding))
+ (define val (uri-decode (substring str (1+ idx)) encoding: encoding))
+ (cons* (-> key string->symbol symbol->keyword) val list))
+ '() (string-split query-string #\&))))