Commit02f3dbd7Recorded25 Mar 2026Repositorysigil-wise

Remove local url-encode-value and build-query-string, import from (sigil http)

Message

The shared implementation in sigil-http handles multi-byte UTF-8 correctly via string->utf8, unlike the local copy which used char->integer.

Changed
 src/wise.sgl | 39 +--------------------------------------
 1 file changed, 1 insertion(+), 38 deletions(-)
Diff
src/wise.sglmodified
@@ -9,6 +9,7 @@
9
(sigil string)
10
(sigil struct)
11
(sigil json)
+12
(only (sigil http) url-encode-value build-query-string)
13
(sigil http client))
14
15
(export ;; Client
@@ -100,44 +101,6 @@
101
(apply string-append (wise-client-base-url client)
102
(map (lambda (p) (string-append "/" p)) parts)))
103
103
;;; URL-encode a query parameter value.
104
(define (url-encode-value s)
105
(let ((len (string-length s)))
106
(let loop ((i 0) (acc '()))
107
(if (>= i len)
108
(list->string (reverse acc))
109
(let ((c (string-ref s i)))
110
(cond
111
((or (char-alphabetic? c)
112
(char-numeric? c)
113
(char=? c #\-)
114
(char=? c #\_)
115
(char=? c #\.)
116
(char=? c #\~))
117
(loop (+ i 1) (cons c acc)))
118
((char=? c #\space)
119
(loop (+ i 1) (cons #\+ acc)))
120
(else
121
(let ((n (char->integer c)))
122
(loop (+ i 1)
123
(append (reverse (string->list
124
(string-append "%"
125
(if (< n 16) "0" "")
126
(number->string n 16))))
127
acc))))))))))
128
129
;;; Build a query string from a list of (key . value) pairs.
130
;;; Pairs with #f values are omitted.
131
(define (build-query-string params)
132
(let ((parts (filter (lambda (p) (cdr p)) params)))
133
(if (null? parts)
134
""
135
(string-append "?"
136
(string-join
137
(map (lambda (p)
138
(string-append (car p) "=" (url-encode-value (cdr p))))
139
parts)
140
"&")))))
104
105
;;; Perform an authenticated GET request and return parsed JSON.
106
;;; Raises an error on HTTP status >= 400, with Wise-specific context.