From 6461d1b45c7431b36393fd56423298c81f7208ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 17 Aug 2020 18:46:21 +0200 Subject: Split module/server into stuff. --- module/web/query.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 module/web/query.scm (limited to 'module/web/query.scm') 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 #\&)))) -- cgit v1.2.3