diff options
author | Mathieu Othacehe <othacehe@gnu.org> | 2020-08-03 15:27:00 +0200 |
---|---|---|
committer | Mathieu Othacehe <othacehe@gnu.org> | 2020-08-03 15:27:00 +0200 |
commit | 2094d68053f606996b2f30a62a2ae4af06851ab6 (patch) | |
tree | 912e7eacde0d631028bbbbccd59e67470e2a9a4f | |
parent | 410d386ea8c0c29829e08a2dcf838de3202e7024 (diff) | |
download | cuirass-2094d68053f606996b2f30a62a2ae4af06851ab6.tar cuirass-2094d68053f606996b2f30a62a2ae4af06851ab6.tar.gz |
http: Handle request parameters with no value.
Handle requests such as "/build/?nr" by ignoring parameters without any
associated value.
* src/cuirass/http.scm (request-parameters): Ignore silently parameters
without an associated value.
* tests/http.scm: Add a corresponding test case.
-rw-r--r-- | src/cuirass/http.scm | 17 | ||||
-rw-r--r-- | tests/http.scm | 7 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm index 39d8711..de27ea5 100644 --- a/src/cuirass/http.scm +++ b/src/cuirass/http.scm @@ -146,16 +146,19 @@ Hydra format." (let* ((uri (request-uri request)) (query (uri-query uri))) (if query - (map (lambda (param) + (fold (lambda (param params) (match (string-split param #\=) ((key param) (let ((key-symbol (string->symbol key))) - (cons key-symbol - (match key-symbol - ('id (string->number param)) - ('nr (string->number param)) - (_ param))))))) - (string-split query #\&)) + (cons (cons key-symbol + (match key-symbol + ('id (string->number param)) + ('nr (string->number param)) + (_ param))) + params))) + (_ #f))) + '() + (string-split query #\&)) '()))) diff --git a/tests/http.scm b/tests/http.scm index 1bcd056..f1d6e46 100644 --- a/tests/http.scm +++ b/tests/http.scm @@ -255,6 +255,13 @@ (test-cuirass-uri "/api/latestbuilds?nr=1&jobset=gnu"))))) + (test-equal "/api/latestbuilds?nr&jobset=gnu" + 500 + (response-code + (http-get + (test-cuirass-uri + "/api/latestbuilds?nr&jobset=gnu")))) + (test-equal "/api/queue?nr=100" `("fake-2.0" ,(build-status scheduled)) (match (json-string->scm |