aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-05-11 20:34:53 +0100
committerChristopher Baines <mail@cbaines.net>2019-05-11 20:34:53 +0100
commit3d004f8597083d7847c340dde55bf41f2efa2d2e (patch)
tree61db5b50b872c9a3875710f52268bc2648fe80f0 /guix-data-service
parentbec838caf95ae154ead22e109217186cfc858670 (diff)
downloaddata-service-3d004f8597083d7847c340dde55bf41f2efa2d2e.tar
data-service-3d004f8597083d7847c340dde55bf41f2efa2d2e.tar.gz
Add #:required and #:multi-value support to parse-query-parameters
Diffstat (limited to 'guix-data-service')
-rw-r--r--guix-data-service/web/query-parameters.scm29
1 files changed, 28 insertions, 1 deletions
diff --git a/guix-data-service/web/query-parameters.scm b/guix-data-service/web/query-parameters.scm
index 0809791..45353b9 100644
--- a/guix-data-service/web/query-parameters.scm
+++ b/guix-data-service/web/query-parameters.scm
@@ -59,7 +59,8 @@
accepted-query-parameters)
(define request-query-parameters
(let ((query (uri-query (request-uri request))))
- (if query
+ (if (and query
+ (not (string-null? query)))
(map (match-lambda
((name . value)
(cons (string->symbol name)
@@ -75,6 +76,32 @@
((_ . "") #f)
((_ . value) (cons name
(processor value)))))
+
+ ((name processor #:required)
+ (match (assq name request-query-parameters)
+ (#f (cons name
+ (make-invalid-query-parameter
+ #f "this value is required.")))
+ ((_ . "") (cons name
+ (make-invalid-query-parameter
+ #f "this value is required.")))
+ ((_ . value) (cons name
+ (processor value)))))
+
+ ((name processor #:multi-value)
+ (match (filter-map
+ (match-lambda
+ ((k . value)
+ (and
+ (eq? k name)
+ (match value
+ (#f #f)
+ ("" #f)
+ (value (processor value))))))
+ request-query-parameters)
+ (() #f)
+ (x (cons name x))))
+
((name processor #:default default)
(match (assq name request-query-parameters)
(#f (cons name default))