diff options
Diffstat (limited to '')
-rw-r--r-- | module/server/macro.scm | 11 | ||||
-rw-r--r-- | module/server/util.scm | 6 |
2 files changed, 11 insertions, 6 deletions
diff --git a/module/server/macro.scm b/module/server/macro.scm index ba70a484..99272a75 100644 --- a/module/server/macro.scm +++ b/module/server/macro.scm @@ -87,8 +87,13 @@ (append (parse-query r:query) - (when (memv 'application/x-www-form-urlencoded - (or (assoc-ref r:headers 'content-type) '())) - (parse-query (uri-decode (bytevector->string body "UTF-8"))))))))) + (let ((content-type (assoc-ref r:headers 'content-type))) + (when content-type + (let ((type (car content-type)) + (args (cdr content-type))) + (when (eq? type 'application/x-www-form-urlencoded) + (let ((encoding (or (assoc-ref args 'encoding) "UTF-8"))) + (parse-query (bytevector->string body encoding) + encoding))))))))))) (lambda* (a b #:optional new-state) (values a b (or new-state state)))))))) diff --git a/module/server/util.scm b/module/server/util.scm index ada4f266..58a11ec3 100644 --- a/module/server/util.scm +++ b/module/server/util.scm @@ -4,14 +4,14 @@ :use-module (web uri)) -(define-public (parse-query query-string) +(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))) - (define val (uri-decode (substring str (1+ idx)))) + (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 #\&)))) |