diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-08-17 18:46:21 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-08-17 18:46:21 +0200 |
commit | 6461d1b45c7431b36393fd56423298c81f7208ae (patch) | |
tree | d712742e3a72c57c4410131ae4ff10af429e7812 /module/web/query.scm | |
parent | Fixes. (diff) | |
download | calp-6461d1b45c7431b36393fd56423298c81f7208ae.tar.gz calp-6461d1b45c7431b36393fd56423298c81f7208ae.tar.xz |
Split module/server into stuff.
Diffstat (limited to 'module/web/query.scm')
-rw-r--r-- | module/web/query.scm | 16 |
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 #\&)))) |