diff options
-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" |