diff options
author | Arun Isaac | 2022-12-24 23:01:18 +0000 |
---|---|---|
committer | Arun Isaac | 2022-12-24 23:01:18 +0000 |
commit | f0cef5898e5e9b9149f6bb71df056c59c357d1e6 (patch) | |
tree | a959b97e5c084dcf1eaeed9daeec399b9077b931 | |
parent | 49e8367d19ba921063d350559f4a7bb9d2ab55cc (diff) | |
download | tissue-f0cef5898e5e9b9149f6bb71df056c59c357d1e6.tar.gz tissue-f0cef5898e5e9b9149f6bb71df056c59c357d1e6.tar.lz tissue-f0cef5898e5e9b9149f6bb71df056c59c357d1e6.zip |
web: Move query string utilities.
* tissue/web/server.scm (query-parameters, query-string): Move to ...
* tissue/utils.scm: ... here. Import (ice-9 match) and (web uri).
-rw-r--r-- | tissue/utils.scm | 28 | ||||
-rw-r--r-- | tissue/web/server.scm | 22 |
2 files changed, 27 insertions, 23 deletions
diff --git a/tissue/utils.scm b/tissue/utils.scm index 59c0b0a..14cc243 100644 --- a/tissue/utils.scm +++ b/tissue/utils.scm @@ -21,7 +21,9 @@ #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) #:use-module (ice-9 filesystem) + #:use-module (ice-9 match) #:use-module (ice-9 popen) + #:use-module (web uri) #:export (string-blank? string-contains? string-remove-prefix @@ -31,7 +33,9 @@ call-with-temporary-directory call-with-output-pipe get-line-dos-or-unix - memoize-thunk)) + memoize-thunk + query-parameters + query-string)) (define (string-blank? str) "Return #t if STR contains only whitespace. Else, return #f." @@ -120,3 +124,25 @@ ports) in that it also supports DOS line endings." (unless result (set! result (thunk))) result))) + +(define (query-parameters query) + "Return an association list of query parameters in web QUERY string." + (if query + (map (lambda (parameter) + (match (string-split parameter #\=) + ((key value) + (cons (uri-decode key) + (uri-decode value))))) + (string-split query #\&)) + '())) + +(define (query-string parameters) + "Return a query string for association list of PARAMETERS." + (string-join + (map (match-lambda + ((key . value) + (string-append (uri-encode key) + "=" + (uri-encode value)))) + parameters) + "&")) diff --git a/tissue/web/server.scm b/tissue/web/server.scm index f5e601b..1e6d04b 100644 --- a/tissue/web/server.scm +++ b/tissue/web/server.scm @@ -198,28 +198,6 @@ operators " (ul (@ (class "search-results")) ,@results)))) -(define (query-parameters query) - "Return an association list of query parameters in web QUERY string." - (if query - (map (lambda (parameter) - (match (string-split parameter #\=) - ((key value) - (cons (uri-decode key) - (uri-decode value))))) - (string-split query #\&)) - '())) - -(define (query-string parameters) - "Return a query string for association list of PARAMETERS." - (string-join - (map (match-lambda - ((key . value) - (string-append (uri-encode key) - "=" - (uri-encode value)))) - parameters) - "&")) - (define (log-request request) "Log @var{request} to standard output." (format #t "~a ~a\n" |